0
後可觀察的項目可以不明白爲什麼預期以下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)
}
我由projectName
分組的和要打印的每張的項目項目。但是,當我運行此代碼時,它只打印:
projectName: aaa
(aaa,[email protected])
projectName: bbb
(bbb,[email protected])
沒有######### event in project
打印。
我不明白爲什麼,有什麼我錯過了?