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

Allowing fn.op operations to take more than two args #16

Closed dillonforrest closed 8 years ago

dillonforrest commented 10 years ago

I'm envisioning something along the lines of:

expect( fn.op['+'](1, 2, 3, 4, 5) ).to.equal(15);
expect( fn.op['-'](8, 4, 1) ).to.equal(3);

The implementation would simply be reducing all the arguments.

I also feel that fn.op['>'] and fn.op['<'] would be incredibly useful see if a series of numbers are ascending or descending:

expect( fn.op['<'](1, 2) ).to.be.true;

// descending
var testScores = [88, 77, 66, 55]
expect ( fn.apply( fn.op['>'], testScores ) ).to.be.true;

I'd implement fn.op['>'] and fn.op['<'] with simple recursion.

What are your thoughts?

dillonforrest commented 10 years ago

To clarify, I'd be more than happy to submit another PR with these features if you think they have merit! My suggested PR here is very lisp-y.

eliperelman commented 10 years ago

The fn.op methods aren't officially documented yet as I'm not exactly sure how the API would look, and these are the kinds of discussions I need around it. I'd like to get more weigh in from users about the op methods and how they would envision these APIs to work.

dillonforrest commented 10 years ago

Sounds good! If or when I submit a PR for this particular feature, this will NOT break any existing functionality. It will only add onto it!! :D

eliperelman commented 10 years ago

Luckily there isn't really anything that should be depending on fn.op anyways since it's undocumented and if I recall isn't used anywhere internally, so I don't mind that this would be breaking if it's a better API.

CrowdHailer commented 8 years ago

@dillonforrest Anything become of this suggestion?

dillonforrest commented 8 years ago

@CrowdHailer nope!