Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support index reference in reduce function #46

Open
claytonflesher opened this issue Dec 13, 2022 · 1 comment
Open

Support index reference in reduce function #46

claytonflesher opened this issue Dec 13, 2022 · 1 comment

Comments

@claytonflesher
Copy link

claytonflesher commented Dec 13, 2022

It would be nice, and a lot less verbose in some use cases, if we could support the index of a collection as an optional argument in the reduce function.

The implicit variable would be $$$ as it is in pluck, and if you named the variable it would be the third argument, making the new interface for reduce be:

(item, acc = [], index)

while still supporting the existing:
(item, acc = [])

By making the index an optional third argument that isn't defined unless referenced in the function call, it should make existing implementations backwards compatible while providing a useful variable for complex reduce use cases.

@machaval
Copy link
Contributor

machaval commented Jan 9, 2023

Agree this is very useful addition though it can not be added to the current reduce function without breaking compatibility, so this will require the introduction of a new reduce funtion like reduceWithIndex or something like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants