babel-plugin-pipe-composition

0.1.1 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.13latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.13
0.1.02

Package Sidebar

Install

npm i babel-plugin-pipe-composition

Weekly Downloads

5

Version

0.1.1

License

MIT

Last publish

Collaborators

  • michaelmitchell