Skip to content

Instantly share code, notes, and snippets.

@dborovikov
Created August 23, 2016 12:47
Show Gist options
  • Select an option

  • Save dborovikov/902600934b76e5d65df51d1bde4f2ce5 to your computer and use it in GitHub Desktop.

Select an option

Save dborovikov/902600934b76e5d65df51d1bde4f2ce5 to your computer and use it in GitHub Desktop.
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