babel-plugin-holes
This plugin is made to bring the powerful expressivity of Scala functions to JavaScript. It provides a powerful system of holes to help on functional programming and function composition, enforcing the point-free style.
It's very well tested and has consistent rules that shouldn't break when used with other plugins. You can also abstract the native JavaScript operations with it without overheads!
Examples
// Binary operatorsconst add = _ + _const increment = _ + 1 console // 300console // 1001 // Unary operatorsconst negate = -_ console // -10 // Operators as functionsconst at = __const call = console // 10 // 'Hello!' // Identity functionconst id = _ console // 'frobnicate' // Method callsconst toString = _const toHexString = _ console // 10console // 'a' // Binary property accessconst goodPassword = _length >= 8const ageSum = _age + _age console // trueconsole // 51 // Binary method callconst ellipsize = _ + '...' console // 100...
It works on identifiers, simple members, computed members, calls, binary and unary expressions, so you can compose functions that take more parameters, for example:
const assocOne = console // { value: 1 }
Disabling in current scope
If you want to use the original underscore, you can disable this plugin in
current scope (and its children scopes) using 'no holes'
directive.
Options
You can pass your own curry function with { curry: 'curry' }
. The generated functions
will use it, so:
const add = _ + _
will emit:
const add =
Installation
$ npm install --save-dev babel-plugin-holes
Usage
.babelrc
(Recommended)
Via .babelrc
Via CLI
$ babel --plugins holes script.js
Via Node API
;
Observation
Using ++
and --
has no warranties because Babel code generator has a bug that emits wrong
code for a correct AST node. Their use is not recommended.
License
MIT