Skip to content

Instantly share code, notes, and snippets.

@sadache
Forked from gre/code.scala
Created December 12, 2011 09:27
Show Gist options
  • Select an option

  • Save sadache/1466170 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

gre commented Dec 12, 2011

Thanks Sadek :)

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

@sadache
Copy link
Copy Markdown
Author

sadache commented Dec 12, 2011 via email

@sadache
Copy link
Copy Markdown
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