无法理解为什么以下rxscala代码无法按预期工作:
import rx.lang.scala.Observable
object MyTest extends App {
case class ProjectEvent(projectName: String, description: String)
val projectEvents: Observable[ProjectEvent] = Observable.just(
ProjectEvent("aaa", "d1"),
ProjectEvent("bbb", "d2"),
ProjectEvent("aaa", "d3")
)
lazy val grouped = projectEvents.groupBy(_.projectName).map { case (projectName, eventsOfThisProject) =>
println("projectName: " + projectName)
eventsOfThisProject.foreach(x => "######### event in project " + projectName + ": " + x)
(projectName, eventsOfThisProject)
}
grouped.foreach(println)
}
我按 分组projectEvents
并projectName
希望打印每个项目的项目。但是当我运行这段代码时,它只打印:
projectName: aaa
(aaa,rx.lang.scala.JavaConversions$$anon$2@49de17f4)
projectName: bbb
(bbb,rx.lang.scala.JavaConversions$$anon$2@52f6438d)
没有######### event in project
印刷品。
我不明白为什么,我错过了什么吗?