Chainable Curry Without Modifying Prototypes
01 July 2014
“OMG another curry article!?”
Got it out of your system? Cool. Let’s continue.
Functional programming makes heavy use of partial application and its simpler cousin, curry. I’m not here to rehash the debate over conflating terms, just offer an alternative pattern for adding curry to your application in es5 or es6 without modifying the native prototypes.
To use this method, you need to add it to a function, like this:
curry adds itself to the returned function when you use it, so its chainable.
We can also still use call and apply as we normally would.
Our implementation gets even simpler using es6’s rest and spread operators
See the rest of the gist for tests (es6).
EDIT: I turned this into an npm module.