Skip to content

Instantly share code, notes, and snippets.

@tzachz
Last active July 24, 2018 21:57
Show Gist options
  • Save tzachz/63abefe8bdfd5adcbf96d24be12eadc1 to your computer and use it in GitHub Desktop.
Save tzachz/63abefe8bdfd5adcbf96d24be12eadc1 to your computer and use it in GitHub Desktop.
CompositionPost3
// 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