voddan
06/13/2019, 12:03 PMlist.take(n)
in a way that would remember the last accessed position and give me the next m
elements on a consecutive list.take(m)
https://stackoverflow.com/questions/56578561/how-can-i-take-varying-chunks-out-of-a-kotlin-sequence
My solution was to produce an Iterator
from the list and use take(n)
on it. Unfortunately that produces a of-by-one error because of the way take
is implemented in stdlib. To fix this one would have to modify a few lines in the [implementation](https://github.com/JetBrains/kotlin/blob/41ce88cb9b8e32da6121e79c229b2563f46fd161/libraries/stdlib/common/src/generated/_Collections.kt#L778 )
replacing
for (item in this) {
if (count++ == n)
break
list.add(item)
}
with
for (item in this) {
list.add(item)
if (++count == n)
break
}
Could such a change be considered?ilya.gorbunov
06/13/2019, 2:57 PMn==0
, then I think the change won't hurt.voddan
06/13/2019, 5:09 PMilya.gorbunov
06/13/2019, 5:19 PM