Last active
August 29, 2015 13:57
-
-
Save matthandlersux/9403412 to your computer and use it in GitHub Desktop.
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
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