Skip to content

Instantly share code, notes, and snippets.

@eamelink
Created July 14, 2014 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eamelink/bd425f0b2f3cee8e702c to your computer and use it in GitHub Desktop.
Save eamelink/bd425f0b2f3cee8e702c to your computer and use it in GitHub Desktop.
Example of converting Future[Try[A]] to EitherT
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