pipeoperator
v0.1.1
Published
Pipelines for javascript. Inspired by the elixir pipe operator.
Maintainers
Readme
pipeoperator
A library that creates pipelines in JavaScript. It works exactly like the pipe operator from Elixir or Bash.
Installation
npm install pipeoperatorimport { pipeline } from 'pipeoperator';Usage
const pipedValue = pipeline(value)
.pipe(doSomething)
.pipe(doSomethingElse)
.pipe(doAnotherThing)
.pipe(value => value.map(v => v.property))
.result();
function doSomething(arg) { /* ... */ }
function doSomethingElse(arg) { /* ... */ }
function doAnotherThing(arg) { /* ... */ }pipe() also takes additional arguments that are passed into the called function:
const total = pipeline(1)
.pipe(sum, 3, 2)
.pipe(sum, 4)
.result();
// total === 10
function sum(...args) {
return args.reduce((total, number) => {
return total + number;
}, 0);
}