iter icon indicating copy to clipboard operation
iter copied to clipboard

Function proposal - at/get()

Open marcospassos opened this issue 5 years ago • 2 comments

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.

marcospassos avatar Aug 12 '18 19:08 marcospassos

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.

marcospassos avatar Aug 12 '18 19:08 marcospassos

Isn't this covered by slice?

slice($iterable, 15, 1)

SamMousa avatar Sep 11 '20 11:09 SamMousa