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

Add fn.curryRight #15

Closed dillonforrest closed 10 years ago

dillonforrest commented 10 years ago

Addresses #9.

Even though @eliperelman and I discussed using fn.flip, I ended up using fn.reverse on the arguments. I know this leads to more code, but please hear me out. :)

After I wrote my fail-first tests, I implemented fn.curryRight simply with this:

fn.curryRight = fn.flip(fn.curry);

Due to the recursive nature of fn.curry, this simple use of fn.flip didn't work. To make all my tests pass and enable the same recursive functionality, I had to basically duplicate the code in fn.curry. So the advantage to using fn.reverse with all the additional code is that fn.curryRight behaves as expected. The disadvantage is that the code is no longer dry, and that makes me sad.

I'm happy to resubmit my pull request if you're okay with me abstracting out the recursive curry function inside fn.curry so that we can reuse it in both fn.curry and fn.curryRight.

Otherwise, I tried my best to stay within the pre-existing style, including using tabs over spaces.

What are your thoughts?

eliperelman commented 10 years ago

If you can, I would like to see a more generic solution, if you think it would be simple enough. Having it be more DRY couldn't hurt. If you don't have time, I could take your code and see what I could come up with.

eliperelman commented 10 years ago

Apologies, I made the comments on the build file and not the src file. facepalm

dillonforrest commented 10 years ago

@eliperelman hehe it happens to all of us!! :)

I'll work on my next patch later this week or weekend. Thanks for the feedback!! :D

eliperelman commented 10 years ago

Absolutely, and thanks for your contributions!

eliperelman commented 10 years ago

Thanks for the PR! These will be moved to npm and the version bumped once I can document them.

dillonforrest commented 10 years ago

My pleasure, buddy! :D

eliperelman commented 10 years ago

Now live with v0.8.0 with fed32709942e7d988c377e7bf3c120fde3a1d72b. Updates to docs forthcoming.

dillonforrest commented 10 years ago

Awesome, thanks @eliperelman! Congratulations on 0.8.0!! :D