0
0
JRJose Romero
comprehensionpredicatefutureβ’β’β’
Idiomatic solution to have filter, conditionals, predicates in Futures' for-comprehension
Example of usage:
val f2 = for {
i <- f1
_ <- predicate( i == 2 )(new Exception("Test2"))
j <- f3 // f3 will only run if the predicate is true
} yield "Test1"
import scala.concurrent.Future
def predicate(condition: Boolean)(fail: Exception): Future[Unit] =
if (condition) Future( () ) else Future.failed(fail)