Skip to content

Instantly share code, notes, and snippets.

@atamborrino
Created August 23, 2016 14:09
Show Gist options
  • Select an option

  • Save atamborrino/61afee05b81ab5823078a2b608a5555e to your computer and use it in GitHub Desktop.

Select an option

Save atamborrino/61afee05b81ab5823078a2b608a5555e to your computer and use it in GitHub Desktop.
Sequential traverse
def sequentialTraverse[A, B](as: Seq[A])(f: A => Future[B]): Future[Seq[B]] = {
as.foldLeft(Future.sucessful(Vector.empty[B])) { (futAcc, a) =>
for {
acc <- futAcc
b <- f(a)
} yield acc :+ b
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment