Currying
Note: Unless otherwise stated, all multi-argument functions in PureEval are curried.
curry()
Turns a function into a curried function.
- Type
- Details
Takes a non-curried function as an argument and returns the corresponding curried function.
The curried function accepts one or more arguments at a time. If the number of provided arguments has not yet reached the required number for the original function, it returns another function that continues to accept the remaining arguments.
It is evident that the non-curried function must have a length property that accurately reflects the number of its parameters.
- Example
const foo = (a, b, c) => a + b + c;
curry(foo)(1)(2, 3); //6const foo = (a, b, c) => a + b + c;
curry(foo)(1)(2, 3); //6uncurry()
Uncurries a function, the inverse operation of curry.
- Type
- Details
Takes a function that has been curried via curry as an argument and returns the corresponding uncurried function.
- Example
const foo = (a, b, c) => a + b + c;
uncurry(curry(foo)(1)); //(b, c) -> a + b + cconst foo = (a, b, c) => a + b + c;
uncurry(curry(foo)(1)); //(b, c) -> a + b + c