Skip to content

Instantly share code, notes, and snippets.

@sadache
Forked from gre/code.scala
Created December 12, 2011 09:27
Show Gist options
  • Save sadache/1466170 to your computer and use it in GitHub Desktop.
Save sadache/1466170 to your computer and use it in GitHub Desktop.
Play20 Promise sequence function
// What is a Promise sequence function ?
// A function which transform a List[Promise[A]] into a Promise[List[A]]
// First naive implementation. It's a synchronous implementation (blocking).
def sequencePromises[A](list: List[Promise[A]]): Promise[List[A]] =
list.foldLeft(Promise.pure(Promise[List[A]]()))((s,p) => s.flatMap( s => p.map(a => s :+ a)))
//should be in the lines of this, didn't try to typecheck it though.
@sadache
Copy link
Author

sadache commented Dec 12, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment