Created
February 15, 2013 00:14
-
-
Save dschobel/4957600 to your computer and use it in GitHub Desktop.
gathering Scala futures
This file contains 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
def gather_futures[A](xs: Seq[Future[A]]): Future[Seq[A]]= { | |
def combine[A,B,C](f1: Future[A], f2: Future[B])(f: (A,B) => C): Future[C] ={ | |
for(a <- f1; b <- f2) | |
yield f(a,b) | |
} | |
xs.foldLeft(Future{Seq[A]()}){(acc: Future[Seq[A]],x: Future[A]) => combine(x,acc)((a: A,b: Seq[A]) => b ++ Seq(a))} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment