Richard Searle


scalaz contrib and Futures

24 Jul 2013

The canonical combined Future example is
def c(i:Int):Future[Int] = ...
val f1 = c(5)
val f2 = c(2)
i1 <- f1
i2 <- f2
yield i1+i2
Creating the Futures within the for-comprehension would be much tidier, but then they would execute sequentially ruining the entire purpose. The scalaz contrib project provides support for Scala 2.10 futures, allowing more expressive coding for some tasks. This applicative functor expression is equivalent to the above code.
val r:Future[Int] = (c(5) |@| c(1))(_ + _)