Last active
July 24, 2018 21:57
-
-
Save tzachz/63abefe8bdfd5adcbf96d24be12eadc1 to your computer and use it in GitHub Desktop.
CompositionPost3
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
// Introduce a flip method: it looks tricky, but as usual it just "follows the types": | |
private def flip[L, R](eitherFuture: Either[L, Future[Either[L, R]]]): Future[Either[L, R]] = { | |
eitherFuture.fold[Future[Either[L, Either[L, R]]]]( | |
left => Future.successful[Either[L, Either[L, R]]](Left(left)), | |
right => right.map(Right(_)) | |
).map(_.joinRight) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment