A better syntax for recovery from a for comprehension
I have a number of functions that return a future that is the result of a for comprehension, but i need to need to recover from some possible failures on the way out. The standard syntax seems to capture the for comprehension as an intermediate results like so: def fooBar(): Future[String] = { val x = for { x <- foo() y <- bar(x) } yield y x.recover { case SomeException() => "bah" } } The best alternative to I've found is to wrap the whole for comprehension in parentheses: def fooBar(): Future[String] = (for { x <- foo() y <- bar(x) } yield y).recover { case SomeException() => "bah" } This