Skip to content

Instantly share code, notes, and snippets.

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

  • Save dborovikov/95c8fb4576e9439c81f52d6383c28d55 to your computer and use it in GitHub Desktop.

Select an option

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