Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2016 11:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
the description for this gist
val f1: Future[Int] = Future { Thread.sleep(100); 1 }
val f2: Future[Int] = Future { Thread.sleep(1000); 2 }
val f3: Future[Int] = Future { Thread.sleep(100); 1 }
val f4: Future[Int] = Future { Thread.sleep(1000); 2 }
import com.thoughtworks.each.Monadic._
import scalaz.std.scalaFuture._
val sum = monadic[Future] {
f1.each + f2.each + f3.each + f4.each
}
sum.onSuccess { case s => println(s"Example 1: $s") }
// prints 6 after one second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment