Last active
June 1, 2021 09:36
-
-
Save princefishthrower/21f96f9224de98a061142f188d852215 to your computer and use it in GitHub Desktop.
pipe.js - execute as many functions as needed in series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pipe.js - execute as many functions as needed in series | |
// from https://egghead.io/lessons/react-create-a-pipe-function-to-enable-function-composition | |
// usage: | |
// const addTwo = (a, b) => console.log(a + b); | |
// const addThree = (a, b, c) => console.log(a + b + c); | |
// pipe(addTwo(1, 2), addThree(3, 4, 5)); | |
// 3 | |
// 12 | |
const combine = (f, g) => (...args) => g(f(...args)); | |
export const pipe = (...fns) => fns.reduce(combine); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment