const pipeAsync = (...fns) => async (value) => {
console.log('fns', fns)
return await fns.reduce((sum, fn) => {
if (typeof fn !== 'function') {
throw new TypeError('fn is not a function');
}
return Promise.resolve(sum).then(fn);
}, value);
}
const add = (numArr) => {
return numArr.reduce((acc, num) => acc + num, 0);
}
const multiplyByTen = (num) => {
return num * 10;
}
const addOne = (num) => {
return num + 1;
}
(async () => {
/* */
const result = await pipeAsync(add, multiplyByTen, addOne)([1, 2, 3, 4, 5]);
console.log('-'.repeat(50), 'result', result);
})();
Created
February 27, 2020 17:45
-
-
Save nkhil/3f3f8c2319488d2ea6e66b8ad9e042d9 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment