Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Created September 22, 2015 01:37
Show Gist options
  • Select an option

  • Save paulosuzart/f37332ee99d22e8d829c to your computer and use it in GitHub Desktop.

Select an option

Save paulosuzart/f37332ee99d22e8d829c to your computer and use it in GitHub Desktop.
orElse
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