master | develop | npm |
---|---|---|
it-curry
it-curry
offers a generator based unbounded currying of functions and async functions of arity > 1
foo =
Because the pattern is flexible and interesting, it-curry also exposes drip
bar =
Accepts a function foo
of arity
n, returns a sink
function that you can call as many times as you need with as many arguments as you have to, internally the original function foo will be called with arguments
of length n, hiding the complexity of the pagination away from your client code.
Upon calling the sink function
, i.e. bar() with no arguments, the generator terminates.
Both curry
and drip
accept an extra argument len
that defaults to fn.length (the number of mandatory arguments for the wrapped function, a.k.a the arity)
acurry
is the async version of curry, which curries async functions
adrip
is the async version of drip, which returns an async sink that drips into an async function
Usage
const curry = ; let foo = ;// call foo up to bar.length times, only executes bar when all required arguments are satisfied foo = ;foo = ;...const result = ;// result of executing bar with n arguments, where n >= bar.length // See test case below for usage patterns
const drip = ; const result = ; const foo = { console; result}; const bar = ; ;;;;; console;
Try it out online
here
Changelog
1.3.0 (2018-11-14)
Features
acurry, adrip: async version of both curry and drip (51354b7)
1.2.0 (2018-11-13)
Features
curry, drip: accept len from user, defaults to fn.length (arity) (2e8ed15)
Example
curry
const curry = ; ; ;
drip
const drip = ; ; ;
Possible use cases
- currying
- curried function pipeline
- deferred execution by currying with an extra dummy last argument.
- internal pagination into a handler of arity n
Run the tests
npm test
FAQs
Build Targets
Currently the following target build environments are configured for babel-preset-env plugin
"targets": {
"node": 4.3,
"browsers": ["last 10 versions", "ie >= 7"]
}
In case this turns out to be not generous enough, more backward compatible babel transpilation targets would be added.
Roadmap
- bigger and better
- rule'em all
Contributing
See CONTRIBUTING.md