Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Last active August 29, 2015 13:57
Show Gist options
  • Save matthandlersux/9403412 to your computer and use it in GitHub Desktop.
Save matthandlersux/9403412 to your computer and use it in GitHub Desktop.
package util
object FutureOption {
implicit class WithFutureOption[A](self: Future[Option[A]]) {
def flatMapOption[T](e: => Exception)(f: A => Future[T]): Future[T] = {
self flatMap {
_ map f getOrElse Future.failed(e)
}
}
def mapOption[T](e: => Exception)(f: A => T): Future[T] = {
self map {
_ map f getOrElse (throw e)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment