Created
August 24, 2017 06:55
-
-
Save mattroberts297/ef2326d2493dedcbd78eb098c7af3cc2 to your computer and use it in GitHub Desktop.
AlternativeFutureExample.scala and WontCompileFutureExample.scala
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
import scala.concurrent.{ExecutionContext, Future} | |
object AlternativeFutureExample { | |
def foobar(implicit ec: ExecutionContext): Future[String] = { | |
for { | |
f <- Future.failed(new RuntimeException("Foo")) | |
} yield { | |
f | |
} | |
} recover { | |
case _: RuntimeException => "Bar" | |
} | |
} |
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
import scala.concurrent.{ExecutionContext, Future} | |
object WontCompileFutureExample { | |
def foobar(implicit ec: ExecutionContext): Future[String] = { | |
for { | |
f <- Future.failed(new RuntimeException("Foo")) | |
} yield { | |
f | |
} recover { | |
case _: RuntimeException => "Bar" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also see original: https://gist.github.com/mattroberts297/7969634d981b920a492617dbf7ed747d