Skip to content

Instantly share code, notes, and snippets.

@mattroberts297
Created August 24, 2017 06:55
Show Gist options
  • Save mattroberts297/ef2326d2493dedcbd78eb098c7af3cc2 to your computer and use it in GitHub Desktop.
Save mattroberts297/ef2326d2493dedcbd78eb098c7af3cc2 to your computer and use it in GitHub Desktop.
AlternativeFutureExample.scala and WontCompileFutureExample.scala
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"
}
}
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"
}
}
}
@mattroberts297
Copy link
Author

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