Created
September 22, 2015 01:37
-
-
Save paulosuzart/f37332ee99d22e8d829c to your computer and use it in GitHub Desktop.
orElse
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
| implicit class OrElseHelper[S, Z](from: (S => Future[Option[Z]])) { | |
| // TODO: Verify if this helper is generalized enough to move to a more central generic area. | |
| def orElse(to : (Z => Future[Z]))(s : S)(c : Z): Future[Either[Future[Z],Future[Z]]] = { | |
| from(s) flatMap { | |
| case None => Future.successful(Left(to(c))) | |
| case Some(someValue) => Future.successful(Right(Future.successful(someValue))) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment