Skip to content

Instantly share code, notes, and snippets.

@tzachz
Created July 20, 2018 20:31
Show Gist options
  • Save tzachz/95467961876d5c25340e1657f3175048 to your computer and use it in GitHub Desktop.
Save tzachz/95467961876d5c25340e1657f3175048 to your computer and use it in GitHub Desktop.
CompositionPostInline
// first attempt: let's just write it down and make the compiler happy:
def processRequest(a: A): Future[Result] = f1(a).flatMap {
case Right(b) => f2(b).flatMap {
case Right(c) => f3(c).flatMap {
case Right(d) =>
f4(d).map(either => either.getOrElse(either.left.get))
case Left(f) => Future.successful(f) // we "satisfy" Future.flatMap by wrapping
// the left result with a successful future
}
case Left(f) => Future.successful(f) // and again..
}
case Left(f) => Future.successful(f) // and again
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment