This plugin allows you to automatically curry arrow functions by defining them as a set of unary functions respectively receiving each argument.
const add = x => y => x + y
const mult3 = a => b => c => a * b * c
Turn into
const add = _curry(2, (x, y) => x + y)
const mult3 = _curry(3, (a, b, c) => a * b * c)
To leave your functions uncurried you have to either use the 'no auto-curry' directive or simply define your arrow functions with multiple arguments at once.
$ npm install --save-dev babel-plugin-auto-curry
.babelrc
{
"plugins": ["auto-curry"]
}
$ babel --plugins auto-curry script.js
require('babel-core').transform('code', {
plugins: ['auto-curry']
});
To use a curry function other than the one implemented by the plugin, you can set the curryFunction
option in your .babelrc
. The custom function must accept a number (the arity) and a function, respectively. Also, don't forget that the function must be in scope, so import it if you have to!
{
plugins: [
["auto-curry", {
"curryFunction": "mySpecialCurry",
}]
]
}
MIT