0.1.1 • Published 8 years ago

babel-plugin-pipe-composition v0.1.1

Weekly downloads
125
License
MIT
Repository
github
Last release
8 years ago

github tag npm version npm license build status known vulnerabilities

babel-plugin-pipe-composition

Overload the bitwise operators (<<) and (>>) to provide to provide F# like pipe forward/backward behavior

This is an alternative to babel-plugin-pipe-operator and babel-plugin-pipe-operator-curry and favors the currying approach.

Examples

import { map, filter } from 'lodash';

const array = [1, 2, 3, 4, 5];

let result = array
  >> map(n => n * 2)
  >> filter(n => n % 3 == 0);

let result = filter(n => n % 3 == 0)
  << map(n => n * 2)
  << array;

Disabling in current scope

If you want to use the original bitwise operators, you can disable this plugin in current scope (and child scopes) using "no pipe" directive

const fn = () => {
  const arr = [1, 2, 3] >> map(n => n + 1);

  return () => {
    "no pipe";

    arr.map(n => n >> 1);
  };
};

const fn = () => {
  const arr =  map(n => n + 1) << [1, 2, 3];

  return () => {
    "no pipe";

    arr.map(n => 1 << n);
  };
};

Installation

$ npm install --save-dev babel-plugin-pipe-composition

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["pipe-composition"]
}

Via CLI

$ babel --plugins pipe-composition script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["pipe-composition"]
});

License

MIT