Skip to content

Instantly share code, notes, and snippets.

@oluies
Created October 9, 2011 12:31
Show Gist options
  • Save oluies/1273632 to your computer and use it in GitHub Desktop.
Save oluies/1273632 to your computer and use it in GitHub Desktop.
Futures.fold
def fs = (0 to 1000) map (i => Future(i, 10000))
def get = Futures.fold(ArrayBuffer.empty[AnyRef], 10000)(fs) {
case (l, i) if i%2==0 => l += i.asInstanceOf[AnyRef]
case (l, _) => l
}.await.result.get.asInstanceOf[ArrayBuffer[Int]].sum
(0 to 1000) foreach (_ => assert(get == 250500))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment