dyn-curry
What? Yet another currying module?
Yes, but this time it is quite different.
Usually currying routines use fn.length
to determine how far the currying should go. This is rather restricting.
Some other modules do something trickier than that, but you still can't effect their choices from inside a function being curried.
Gain full control
curry = require('dyn-curry')
curry([ctx], fn)
Returns a wrapper function.
Inside fn
, return curry
to indicate that the function needs more arguments. It shouldn't usually produce any side effects, because the wrapper will be called each time new chunk of arguments is supplied. Return fast.
Finally, curry
is curried itself! If the first argument is not a function, it will wait for the function to come. (Be careful: if the context is a function indeed, you should pass all of the arguments at once, no currying will happen — sorry!)
Examples
Optional arguments
var hello = ; ; // "Hello!"; // function'Hello!'; // "Hello! Nice jacket!"
Simulating traditional currying
var add = ; ; // function; // function; // 3
String concatenation
var makeSentence = ; var sentence = ; // functionsentence = ; // functionsentence = ; // finally, a string
Blackjack
var blackjack = ; ; // function11; // 215 32 1; // 21; // 42
Install
npm install dyn-curry
License
MIT