1

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.

4

1 に答える 1

3

A1. Enumerator#enumerateそれぞれに対して Iteratee を実行するために使用できます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. を定義する代わりにWriteable[Option[String]]、から抽出Stringします。Option[String]

Ok.stream(
   Enumerator(Option("kiki"), Option("foo"), Option("bar")).map(_.get) >>> Enumerator.eof
)
于 2013-02-13T08:49:17.510 に答える