Created
January 28, 2017 00:00
-
-
Save trane/71c5844b3b0e13f46dad4b212fbc1f31 to your computer and use it in GitHub Desktop.
This file contains 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
object OptionUtils { | |
def fromOption[A](opt: Option[A])(onNone: => Throwable): Future[A] = | |
Future.successful(opt).map(_.getOrElse(throw onNone)) | |
def fromOption[A](opt: Option[A])(onNone: => A): Future[A] = | |
Future.successful(opt).map(_.getOrElse(onNone)) | |
} | |
class OptionOps[A](val self: Option[A]) { | |
def toFuture(onNone: => Throwable): Future[A] = OptionUtils.fromOption(self)(onNone) | |
def toFuture(onNone: => A): Future[A] = OptionUtils.fromOption(self)(onNone) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment