deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

[collections] Pass index to partition callback

Open canac opened this issue 10 months ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe.

I tried to use partition and expected to be able to access the element index like normal array methods, but it isn't passed to the callback.

Describe the solution you'd like

Pass the element index to the partition callback. If the maintainers think this is a good idea, there are other methods in collections that could be passed the index as well. ~~Maybe we should even consider passing in the original array as the third argument to match the signature of most built-in array method callbacks.~~ EDIT: I noticed that most methods accept iterables so passing in the original array does not make sense.

Describe alternatives you've considered

Call .filter twice to partition the array instead.

canac avatar Dec 21 '24 03:12 canac