PaulloClara / pipe-to

A simple implementation of functional pipe in JavaScript.

Home Page:https://www.npmjs.com/package/pipe-to

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pipe To

A simple implementation of functional pipe in JavaScript.

Installation

$ npm install pipe-to
# or
$ yarn add pipe-to

Usage

// sync
const pipe = require("pipe-to");

function double(value) {
  return value * 2;
}

function subtract(value) {
  return value - 1;
}

// standard
console.log(subtract(double(double(2))));

// pipe-to
console.log(pipe(2).to(double, double, subtract));
// async
...

function asyncDouble(value) {
  return new Promise(resolve => resolve(double(value)));
}

function asyncSubtract(value) {
  return new Promise(resolve => resolve(subtract(value)));
}

(async () => {
  // standard
  console.log(await asyncSubtract(await asyncDouble(await asyncDouble(4))));

  // pipe-to
  console.log(await pipe(4).asyncTo(asyncDouble, asyncDouble, asyncSubtract));
})();

About

A simple implementation of functional pipe in JavaScript.

https://www.npmjs.com/package/pipe-to

License:MIT License


Languages

Language:JavaScript 100.0%