In the example below I get the exception java.util.NoSuchElementException: Future.filter predicate is not satisfied
I want to have the result Future( Test2 )
when the check if( i == 2 )
fails. How do I handle filter/if within a for comprehension that deals with composing futures?
Below is a simplified example that works in the Scala REPL.
Code:
import scala.concurrent.Future
import scala.util.{ Try, Success, Failure }
import scala.concurrent.ExecutionContext.Implicits.global
val f1 = Future( 1 )
val f2 = for {
i <- f1
if( i == 2 )
} yield "Test1"
f2.recover{ case _ => "Test2" }
f2.value