Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scala> lazy val longComputation = IO{println("Long Computation ...."); 10.some}
- longComputation: scalaz.effect.IO[Option[Int]] = <lazy>
- scala> lazy val shortComputation = IO{println("Short Computation ...."); 2.some}
- shortComputation: scalaz.effect.IO[Option[Int]] = <lazy>
- scala> lazy val shortComputationFail:IO[Option[Int]] = IO{println("Short Computation ...."); none}
- shortComputationFail: scalaz.effect.IO[Option[Int]] = <lazy>
- scala> (shortComputation >>= {o => o.isDefined? o.pure[IO] | longComputation}).unsafePerformIO
- Short Computation ....
- res49: Option[Int] = Some(2)
- scala> (shortComputationFail >>= {o => o.isDefined? o.pure[IO] | longComputation}).unsafePerformIO
- Short Computation ....
- Long Computation ....
- res51: Option[Int] = Some(10)
Advertisement
Add Comment
Please, Sign In to add comment