Created
January 20, 2017 04:39
-
-
Save wjlow/f97eea2b79d9d29611edb1c4066e16c6 to your computer and use it in GitHub Desktop.
traverse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val f: Int => Future[Person] = ??? | |
val ids = List(1,2,3,4,5) | |
val persons: Future[List[Person]] = Future.traverse(ids, f) // parallel computation using Applicative | |
val persons2: List[Future[Person]] = ids map (id => f(id)) // sequential computation | |
persons2.sequence : Future[List[Person]] // now you can wait on one Future instead of many Futures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment