Created
August 23, 2016 12:47
-
-
Save dborovikov/902600934b76e5d65df51d1bde4f2ce5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cats.data.{ Xor, XorT } | |
| import cats.std.future._ | |
| import cats.syntax.xor._ | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.duration.Duration | |
| import scala.concurrent.{ Await, Future } | |
| object XorDemo extends App { | |
| sealed trait Error | |
| def f1(): Future[Xor[Error, Int]] = { | |
| Future.successful(3.right) | |
| } | |
| def f2(): Future[Xor[Error, Int]] = { | |
| Future.successful(5.right) | |
| } | |
| def f3(): Future[Xor[Error, Int]] = { | |
| val z = for { | |
| x <- XorT(f1()) | |
| y <- XorT(f2()) | |
| } yield x + y | |
| z.value | |
| } | |
| println(Await.result(f3(), Duration.Inf)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment