CrowdHailer / fn.js

A JavaScript library built to encourage a functional programming style & strategy. - http://eliperelman.com/fn.js
MIT License
399 stars 30 forks source link

Change ordering of fn.reduce arguments? #12

Closed jpotterm closed 10 years ago

jpotterm commented 10 years ago

I think it would be beneficial to move the accumulator to be the second argument to fn.reduce:

fn.reduce(handler, accumulator, collection)

This would let us do things like:

var sum = fn.partial(fn.reduce, fn.op['+'], 0);
var product = fn.partial(fn.reduce, fn.op['*'], 1);

I think it makes sense to have the accumulator near the handler because it is almost always the identity value of the function being used to accumulate.

If you think this is a good idea, I'd be happy to submit a pull request with this change.

eliperelman commented 10 years ago

At first glance, I do believe that this would be a good change. Does anyone else have any reservations for making this breaking change? If not, then I'd say go ahead with the implementation.

dillonforrest commented 10 years ago

I agree with this change. For what it's worth, that's also the way Clojure implements reduce: http://clojuredocs.org/clojure_core/clojure.core/reduce

CrossEye commented 10 years ago

+1. Definitely the most appropriate order.

On Mon, Mar 10, 2014 at 5:36 PM, Dillon Forrest notifications@github.comwrote:

I agree with this change. For what it's worth, that's also the way Clojure implements reduce: http://clojuredocs.org/clojure_core/clojure.core/reduce

Reply to this email directly or view it on GitHubhttps://github.com/eliperelman/fn.js/issues/12#issuecomment-37237573 .

eliperelman commented 10 years ago

Great, if someone would like to submit a pull request, I'd be happy to review it.

eliperelman commented 10 years ago

This is now in 0.7.0. Remember that this is a breaking change, so upgrading will mean needing to change the order of fn.reduce arguments. Thanks everyone!