CURRY
A curry function without anything too clever (... because hunger is the finest spice)
Why
If you don't know currying, or aren't sold on it's awesomeness, perhaps a friendly blog post will help.
API
curry
var curry = ; //-- creating a curried function is pretty//-- straight forward:var add = ; //-- it can be called like normal: //= 3 //-- or, if you miss off any arguments,//-- a new funtion that expects all (or some) of//-- the remaining arguments will be created:var add1 = ; //= 3; //-- curry knows how many arguments a function should take//-- by the number of parameters in the parameter list //-- in this case, a function and two arrays is expected//-- (fn, a, b). zipWith will combine two arrays using a function:var zipWith = ; //-- if there are still more arguments required, a curried function//-- will always return a new curried function:var zipAdd = ;var zipAddWith123 = ; //-- both functions are usable as you'd expect at any time:; //= [2, 4, 6]; //= [6, 8, 10] //-- the number of arguments a function is expected to provide//-- can be discovered by the .length propertyzipWithlength; //= 3zipAddlength; //= 2zipAddWith123length; //= 1
curry.to
Sometimes it's necessary (especially when wrapping variadic functions) to explicitly provide an arity for your curried function:
var { var nums = slice; return nums;} var sum3 = curry;var sum4 = curry; 3 //= 623 4 //= 10
curry.adapt
It's a (sad?) fact that JavaScript functions are often written to take the 'context' object as the first argument.
With curried functions, of course, we want it to be the last object. curry.adapt
shifts the context to the last argument,
to give us a hand with this:
var delve = ;var delveC = curry; var getDataFromResponse = ;; //= { x: 2 }
curry.adaptTo
Like curry.adapt
, but the arity explicitly provided:
var _ = ;var map = curry;var mapInc = //= [2, 3, 4]
installation
node/npm
npm install curry
amd
;
browser
If you're not using tools like browserify or require.js, you can load curry globally:
∏∏