iter
iter copied to clipboard
Function proposal - at/get()
We have a use case where we need to get a value by its index.
In that sense, I'd like to suggest introducing a function at/get(iterable $iterable, int $index) : ?int
that takes an iterable and returns the item at the specified index.
I'll be glad to provide a PR if welcome.
Alternatively, we can introduce a seek(iterable $iterable, int $index) : \Iterator
, that takes an iterable and returns an iterator at the specified index. The advantages of this approach are iteration deferring on non-seekable iterators and support for both key and value lookup.
Isn't this covered by slice
?
slice($iterable, 15, 1)