Skip to content

PaulloClara/pipe-to

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published