Created
July 14, 2014 09:52
-
-
Save eamelink/bd425f0b2f3cee8e702c to your computer and use it in GitHub Desktop.
Example of converting Future[Try[A]] to EitherT
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
val a, b, c: Future[Try[String]] = ??? | |
val out = for { | |
_ <- a.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error!")) |> EitherT.apply | |
_ <- b.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error 2!")) |> EitherT.apply | |
_ <- c.map(t => \/.fromTryCatch(t.get).leftMap(ex => "Error 3!")) |> EitherT.apply | |
} yield () | |
val result: Future[String \/ Unit] = out.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment