Skip to content

Instantly share code, notes, and snippets.

@sadache
Forked from gre/code.scala
Created December 12, 2011 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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.
@gre
Copy link

gre commented Dec 12, 2011

Thanks Sadek :)

Yours was nearly OK ;)
https://gist.github.com/1466196 ( my re-fork :) )

@sadache
Copy link
Author

sadache commented Dec 12, 2011 via email

@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