带列表的代码:
println(listOf(1, 2, 3).windowed(1))
println(listOf(1, 2, 3).windowed(1) { it })
println(listOf(1, 2, 3).windowed(1) { it.toList() })
结果:
[[1], [2], [3]]
[[3], [3], [3]] //why is there 3 everywhere?
[[1], [2], [3]]
带序列的代码:
println(sequenceOf(1, 2, 3).windowed(1).toList())
println(sequenceOf(1, 2, 3).windowed(1) { it }.toList())
println(sequenceOf(1, 2, 3).windowed(1) { it.toList() }.toList())
结果:
[[1], [2], [3]]
[[], [], []] //why?!
[[1], [2], [3]]
请解释