2
我正在使用玩枚舉/枚舉器發送瀏覽器事件。我的事件是將被序列化爲JSON的案例類。我有類似下面的代碼:測試玩枚舉人
import play.api.libs.iteratee.{Enumeratee, Enumerator, Iteratee}
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Future}
implicit val ex = ExecutionContext.global
case class SomeClass(a: String, b: String, c: List[String])
val someEnumerator: Enumerator[SomeClass] = Enumerator.apply(
SomeClass("a", "b", List("a", "b", "c")),
SomeClass("s", "a", Nil),
SomeClass("g", "g", Nil),
SomeClass("a", "T", List("a", "1", "c")))
val filtering: Enumeratee[SomeClass, SomeClass] = Enumeratee.filter[SomeClass](sc => sc.c.nonEmpty)
val toJson: Enumeratee[SomeClass, String] =
Enumeratee.map[SomeClass] {
sc =>
import org.json4s._
import org.json4s.native.Serialization
implicit val formats = Serialization.formats(NoTypeHints)
Serialization.write(sc)
}
val jsonStream: Enumerator[String] = someEnumerator &> filtering &> toJson
我怎樣才能得到結果和測試filtering
,toJson
和jsonStream
?