Created
July 20, 2018 20:31
-
-
Save tzachz/95467961876d5c25340e1657f3175048 to your computer and use it in GitHub Desktop.
CompositionPostInline
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
// 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