Skip to content

Instantly share code, notes, and snippets.

@langley
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save langley/7bf50e5a86207ba3be4f to your computer and use it in GitHub Desktop.
Save langley/7bf50e5a86207ba3be4f to your computer and use it in GitHub Desktop.
Play Framework 2.2.x Enumerator Example
// Start play, go into the console and copy & paste these lines
import scala.concurrent._
import scala.concurrent.duration._
import scala.language.postfixOps
import play.api.libs.iteratee._
import play.api.libs.concurrent.Execution.Implicits._
val enumerateUsers: Enumerator[String] = {
Enumerator("Guillaume", "Sadek", "Peter", "Erwan")
}
val consume = Iteratee.consume[String]()
val newIteratee: Future[Iteratee[String,String]] = enumerateUsers(consume)
val eventuallyResult: Future[String] = newIteratee.flatMap(i => i.run)
eventuallyResult.onSuccess { case x => println(x) }
// from https://www.playframework.com/documentation/2.2.x/Enumerators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment