babel-plugin-curried-functions
v1.0.3
Published
_Note: This is an experimental plugin made as part of my master thesis with the intent of getting to know the Babel-compiler and its extensibility._
Downloads
7
Readme
babel-plugin-curried-functions
Note: This is an experimental plugin made as part of my master thesis with the intent of getting to know the Babel-compiler and its extensibility.
This plugin adds the reserved keyword curry
which can prefix a function definition in order to make it curried. For the sake of simplicity currying arrow-functions is not supported.
Syntax
In
curry function f(a, b, c) {
...
}
Out
function curry(fn) {
const numParamsRequired = fn.length;
function curryFactory(params) {
return function (...args) {
const newParams = params.concat(args);
if (newParams.length >= numParamsRequired) {
return fn(...newParams);
}
return curryFactory(newParams);
}
}
return curryFactory([]);
}
const a = curry(function f(a, b, c) {
...
});