Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[collections] Pass index to partition callback #6288

Open
canac opened this issue Dec 21, 2024 · 0 comments · May be fixed by #6382
Open

[collections] Pass index to partition callback #6288

canac opened this issue Dec 21, 2024 · 0 comments · May be fixed by #6382

Comments

@canac
Copy link
Contributor

canac commented Dec 21, 2024

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 added a commit to canac/std that referenced this issue Feb 5, 2025
canac added a commit to canac/std that referenced this issue Feb 5, 2025
canac added a commit to canac/std that referenced this issue Feb 5, 2025
@canac canac linked a pull request Feb 5, 2025 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant