Currying made simple.
– and we really mean simple:
; // Got a simple function? const plus = a + b + c::; ; //» 62 3; //» 63; //» 623; //» 6 // Got a monster function? const open = ;const newScript = open::; ;
Installation
npm install curry-this
Usage
Basic usage
The function curry
is invoked using the function bind syntax and returns a curried function.
const add = a + b;const curriedAdd = add::; 2; //» 3
Placeholders
A placeholder _
is a Symbol Symbol('CURRY-THIS-PLACEHOLDER')
.
Placeholders are replaced from left to right, the next call after a placeholder is passed replaces the previous placeholders one by one.
const foo = a b c d; const curriedFoo = foo::; 23; //» [1, 2, 3, 4]
If you pass a placeholder to curry
the length of the function is ignored instead the initial call of curry
defines the length of the curried function.
const foo = values; const curriedFoo = foo::; 23; //» [1, 2, 3]
Arity
The curried function has a fixed arity. Additional arguments aren't passed.
const foo = values; const curriedFoo = foo::; 23 5 6 7; //» [1, 2, 3]
Not experimental usage
You can still use curry-this
without the experimental syntax
const add = a + b;const curriedAdd = curry; 2; //» 3
Or with placeholders
const foo = values; const curriedFoo = curry; 23; //» [1, 2, 3]
API
fn::curry(...args)
Parameters
fn | the function to curry |
---|---|
args | curried arguments or placeholders |
Returns
A curried function.
::
huh?
If you’re wondering what the ::
thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal.
Maintainers
stoeffel | tomekwi |