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

Adding syntactic sugar to reduce #388

Closed
wants to merge 4 commits into from

Conversation

NickHeiner
Copy link

This PR enables the following two syntaxes:

var concatted = _.reduce([['foo', 'bar'], ['baz'], ['batz']], 'concat');
// => ['foo', 'bar', 'baz', 'batz']

and

var product = _.reduce([2, 4, 8], '*');
// => 64

If you like them, I'll also add them to reduceRight. Tests and documentation are included. I can break these out into two separate PRs if you prefer. I tried to follow the existing style conventions but let me know if I can make anything look nicer. I wasn't quite sure where the utility methods should live, so I opted for "as close as possible to where they are used".

@jdalton
Copy link
Member

jdalton commented Nov 3, 2013

We handle callback sugar through _.createCallback which allows ".where" & ".pluck" though _.reduce and _.reduceRight currently don't leverage it. I can make them use it so that further customizations are possible.

@jdalton jdalton closed this Nov 3, 2013
@NickHeiner
Copy link
Author

Even if _.reduce and _.reduceRight leverage _.createCallback, _.createCallback will have to be changed to use this syntax, right? Is this approach so far off that it looks nothing like the way you'd like it done? Or do you not think this is a feature worth having?

Also, apologies for the failing travis build. I was just testing by running node test/test.js, but it looks like I have some compatibility issues.

@jdalton
Copy link
Member

jdalton commented Nov 3, 2013

Even if _.reduce and _.reduceRight leverage _.createCallback, _.createCallback will have to be changed to use this syntax, right?

Yap, but that's why it exists :)

@NickHeiner
Copy link
Author

Would you be amenable to a PR changing _.createCallback to use the new syntax? :)

@jdalton
Copy link
Member

jdalton commented Nov 3, 2013

Not at the moment, I've made it customizable/wrapper for these kinds of things. Though I will make _.reduce and _.reduceRight use it.

@NickHeiner
Copy link
Author

Ok, sounds good.

jdalton added a commit that referenced this pull request Nov 4, 2013
jdalton added a commit that referenced this pull request Sep 25, 2014
@lock
Copy link

lock bot commented Dec 28, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants