popipe
v1.1.0
Published
Small method that behaves like the pipe operator of functional languages.
Downloads
4
Readme
popipe
Small method that behaves like the pipe operator of functional languages.
how to install
$ npm install --save popipe
how to use it
The pipe method takes a variable number of arguments and apply them as transformations to the first argument in a clean way, instead of method calls fall.
import pipe from "popipe"
// or var pipe = require("pipe")
// transformation methods
const doubler = x => x * 2
const incrementer = x => x + 1
const answerOfLife = pipe(5, doubler, doubler, incrementer, doubler)
// 42
If you want to apply additional arguments to transformation methods, use the currying technique having a function that accepts a single parameter as your final result.
const multiplier = y => x => x * y
const answerOfLife = pipe(5, doubler, multiplier(2), incrementer, doubler)
// 42