The following code doesn’t work with Iterator
semantics
val a = 1.to(10).toIterator
println(a.take(10).toList)
println(a.take(10).toList)
The general expectation on any iterator is that first one should give 10 items but the next one should be empty. The List’s toIterator works as expected though
val a = 1.to(10).toList.toIterator
println(a.take(10).toList)
println(a.take(10).toList)
Apparently the bug is because overriding the take and drop in the Elements
in here scala/src/library/scala/collection/IndexedSeqLike.scala at 2.12.x · scala/scala · GitHub
We either should not implement Iterator for Elements or not override take/drop/slice in it.
Or is it intentionally behaving that way?