0.4.3 • Published 7 years ago
@lato/babel-plugin-function-composition v0.4.3
@lato/babel-plugin-function-composition
This plugin is made to work with point-free (tacit) functional programming by composing functions
over piping. It is inspired by the work of babel-plugin-pipe-operator-curry,
but with a very different purpose, with focus on omitting arguments. I've overloaded the operator <<
and >> for that. You can built more complex functions from simple ones.
Examples
import { add, multiply } from 'ramda';
const mul5AndAdd5 = add(5) << multiply(5);Turn into
import { add, multiply } from 'ramda';
const mul5AndAdd5 = ((l, r) => (...a) => l(r(...a)))((add(5)), (multiply(5)));>> is << flipped, and both operators bind to the left in js, so
expr1 << expr2 >> expr3is the same as (but with different order of evaluation):
expr3 << (expr1 << expr2)Thanks to function composition being associative, you can drop the parentheses:
expr3 << expr1 << expr2Disabling in current scope
If you want to use the original shift operators, you can disable this plugin in
current scope (and in children scopes) using 'no composition' directive.
Installation
$ npm install --save-dev @lato/babel-plugin-function-compositionUsage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["@lato/babel-plugin-function-composition"]
}Via CLI
$ babel --plugins "@lato/babel-plugin-function-composition" script.jsVia Node API
require('babel-core').transform('code', {
plugins: ['@lato/babel-plugin-function-composition']
});License
MIT