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

fn.curry working right-to-left rather than left-to-right? #9

Closed dillonforrest closed 10 years ago

dillonforrest commented 10 years ago

Hi there! Just discovered fn.js. Looks awesome!! :)

I noticed that fn.curry ends up currying the arguments from left to right. I'm wondering how you'd feel about currying right-to-left. Standard partial applications already go left to right, so I figure currying right to left would be more composable.

What are your thoughts?

eliperelman commented 10 years ago

@dillonforrest Thanks! I don't see any reason why there couldn't be like a curryRight, pipelineCurry, or variant if there's value in it. In just thinking about the implementation, it should be simple enough as fn.reverse on the arguments, but it would probably take a little refactor on fn.curry to make it easily extensible to a reversed version. Thoughts?

Also, there is already a reversed version of fn.compose with fn.pipeline, just fyi.

dillonforrest commented 10 years ago

@eliperelman I think you're right. There are a ton of options. At the moment, none of them stick out as obvious best choices for me.

I just checked out the source. I think something similar to fn.compose would already be good for fn.curryRight.

Also, this made me realize that maybe a similarly implemented fn.reduceRight would be helpful!

If you'd like, I can submit a pull request later on!

eliperelman commented 10 years ago

I'd absolutely welcome a pull request.

eliperelman commented 10 years ago

@dillonforrest In case you hadn't seen it, there is now fn.flip which reverses the arguments of a given function.

eliperelman commented 10 years ago

Closing for now until there is submitted functionality.

dillonforrest commented 10 years ago

@eliperelman Okay cool, thanks!