Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created April 28, 2018 19:36
Show Gist options
  • Save gclaramunt/a40783e1f1c835a38c7ae2569abd8d3f to your computer and use it in GitHub Desktop.
Save gclaramunt/a40783e1f1c835a38c7ae2569abd8d3f to your computer and use it in GitHub Desktop.
def sequence[A, B](l: Iterable[A])(fn: A ⇒ Future[B])(implicit ec: ExecutionContext): Future[List[B]] =
l.foldLeft(Future(List.empty[B])) {
(previousFuture, next) ⇒
for {
previousResults ← previousFuture
next ← fn(next)
} yield previousResults :+ next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment