Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Created April 4, 2014 08:11
Show Gist options
  • Select an option

  • Save richdougherty/9970239 to your computer and use it in GitHub Desktop.

Select an option

Save richdougherty/9970239 to your computer and use it in GitHub Desktop.
package scala.concurrent
import scala.util.Try
case class FutureTry[+A](future: Future[A]) {
def map[B](f: Try[A] => Try[B])(implicit ec: ExecutionContext): FutureTry[B] = {
FutureTry(future.transform(f))
}
def flatMap[B](f: Try[A] => FutureTry[B])(implicit ec: ExecutionContext): FutureTry[B] = {
FutureTry(future.transformWith(t => f(t).future))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment