For my use case I wanted to have `list.take(n)` in...
# stdlib
v
For my use case I wanted to have
list.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
Copy code
for (item in this) {
        if (count++ == n)
            break
        list.add(item)
    }
with
Copy code
for (item in this) {
        list.add(item)
        if (++count == n)
            break
    }
Could such a change be considered?
i
If there's a guard for
n==0
, then I think the change won't hurt.
v
It does. Should I create an issue and a PR then?
i
Yes, a PR is welcome