Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2016 11:17
Show Gist options
  • Save anonymous/deaf1dd3ed34e991b3cb18c58c4d8519 to your computer and use it in GitHub Desktop.
Save anonymous/deaf1dd3ed34e991b3cb18c58c4d8519 to your computer and use it in GitHub Desktop.
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