1.0.1 • Published 4 years ago

pipe-to v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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));
})();