@devmastery/pipe
v0.0.8
Published
Pipe that works with a mix of Promises and Non-Promises
Downloads
106
Readme
@devmastery/pipe
An implementation of a pipe
function that works with a mix of promises and non-promises.
pipe
is a function that receives a list of functions and returns a new function that executes the given list from left to right passing the result from each previous function to the next.
For example:
const promiseToAddOne = async x => x + 1
const double = x => x * 2
const promiseToDouble = async x => x * 2
const addOneThenDoubleTwice = pipe(
promiseToAddOne,
double,
promiseToDouble
)
addOneThenDoubleTwice(1).then(console.log) // logs 8