Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

renanpvaz/babel-plugin-auto-curry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-auto-curry

This plugin allows you to automatically curry arrow functions by defining them as a set of unary functions respectively receiving each argument.

Examples

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)

Disabling

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.

Installation

$ npm install --save-dev babel-plugin-auto-curry

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["auto-curry"]
}

Via CLI

$ babel --plugins auto-curry script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['auto-curry']
});

Using a custom curry function

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",
    }]
  ]
}

License

MIT

About

Plugin to automatically curry arrow functions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published