Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
Created February 18, 2016 16:38
Show Gist options
  • Save nikolaybotev/097935aadeea0465a038 to your computer and use it in GitHub Desktop.
Save nikolaybotev/097935aadeea0465a038 to your computer and use it in GitHub Desktop.
#!scala
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Success
import scala.util.Failure
val x: Future[Boolean] = Future.successful(true)
val y: Future[Boolean] = Future.successful(false)
val xMapped: Future[Int] = x.map(_ match { case true => 42 case false => throw new Exception("hey") })
xMapped onComplete { case Success(n) => println(s"Success $n") case Failure(e) => println(s"Failure ${e}") }
val yMapped: Future[Int] = y.map(_ match { case true => 42 case false => throw new Exception("hey") })
yMapped onComplete { case Success(n) => println(s"Success $n") case Failure(e) => println(s"Failure ${e}") }
@nikolaybotev
Copy link
Author

showcase how scala Futures integrate with Exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment