Question

I am quite new to Play 2 and am trying Iteratees.

Q1. How can I get an Enumerator[Person] from List[Person]?

Q2. When I try to pass an Enumerator(Option[String]) to Ok.stream I get an error on console stating that

Cannot write an instance of Option[String] to HTTP response. Try to define a Writeable[Option[String]]

Can someone point me in the right direction as to how I can define a Writeable for custom types to HTTP response?

Thanks.

Was it helpful?

Solution

A1. You can use Enumerator#enumerate to run Iteratee for each Person

val persons: List[Person] = List(person0, person1)  
Enumerator.enumerate(persons) |>>> Iteratee.foreach(println _)

https://github.com/playframework/Play20/blob/2.1.0/framework/src/iteratees/src/test/scala/play/api/libs/iteratee/EnumeratorsSpec.scala#L74-L83

A2. Instead of defining Writeable[Option[String]], extract String from Option[String]

Ok.stream(
   Enumerator(Option("kiki"), Option("foo"), Option("bar")).map(_.get) >>> Enumerator.eof
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top