apply the given function if it's a failure
apply the given function if it's a failure
(read as flatMap other)
scala> import sclib.ops.`try`._ scala> import scala.util.Try scala> Try(1/0) res0: Try[Int] = Failure(java.lang.ArithmeticException: / by zero) scala> Try(1/0).flatMapO(_ => "unable to calculate: 1/0".failure) res1: Try[Int] = Failure(java.lang.Exception: unable to calculate: 1/0) scala> Try(1/0).flatMapO(_ => 0.success) res2: Try[Int] = Success(0)
applies ff
if this is a Failure
or sf
if this is a Success
.
applies ff
if this is a Failure
or sf
if this is a Success
.
scala> import sclib.ops.`try`._ scala> "" .failure.fold(_.getMessage)(identity) res0: String = <ERROR>
apply the given function if it's a failure
apply the given function if it's a failure
(read as map other)
scala> import sclib.ops.`try`._ scala> import scala.util.Try scala> Try(1/0) res0: Try[Int] = Failure(java.lang.ArithmeticException: / by zero) scala> Try(1/0).mapO(_ => new java.lang.Exception("unable to calculate: 1/0")) res1: Try[Int] = Failure(java.lang.Exception: unable to calculate: 1/0)
converts a 'Try[A]' to a 'Either[Throwable, A]'
zip two Try's
zip two Try's
returns a Failure
if any of the given Try
s are a Failure
scala> import sclib.ops.`try`._ scala> import scala.util.Try scala> val z = 5.success.zip(11.success) res0: Try[(Int, Int)] = Success(5, 11) scala> z.map(Function.tupled(_ + _)) res1: Try[Int] = Success(16)
extensions on
Try
instances