Created
August 23, 2016 12:43
-
-
Save dborovikov/95c8fb4576e9439c81f52d6383c28d55 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.XorT | |
| import cats.std.future._ | |
| 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(): XorT[Future, Error, Int] = XorT.right[Future, Error, Int] { | |
| Future.successful(3) | |
| } | |
| def f2(): XorT[Future, Error, Int] = XorT.right[Future, Error, Int] { | |
| Future.successful(5) | |
| } | |
| def f3(): XorT[Future, Error, Int] = { | |
| for { | |
| x <- f1() | |
| y <- f2() | |
| } yield x + y | |
| } | |
| println(Await.result(f3().value, Duration.Inf)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment