Skip to content

Instantly share code, notes, and snippets.

@wjlow
Created January 20, 2017 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjlow/f97eea2b79d9d29611edb1c4066e16c6 to your computer and use it in GitHub Desktop.
Save wjlow/f97eea2b79d9d29611edb1c4066e16c6 to your computer and use it in GitHub Desktop.
traverse
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