Advertisement
mitrakov

EitherT composition

Aug 16th, 2019
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.30 KB | None | 0 0
  1. val f1: Future[Either[Error, Int]] = ???
  2. val f2: Future[Either[Error, Int]] = ???
  3. val f3(x: Int, y: Int): Future[String] = ???
  4.  
  5. val eitherT = for {
  6.   x <- EitherT(f1)
  7.   y <- EitherT(f2)
  8.   z <- EitherT(f2(x, y).map(_.asRight[Error]))
  9. } yield z
  10. eitherT.value       // Future[Either[Error, String]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement