JS: Function Pipe 🚀
Here is a function to Pipe Functions similar to shell pipe operator x | y | z
.
(aka, Function Chaining, Postfix Function Composition,)
/* xah_pipe(x) → x xah_pipe(x,f) → f(x) xah_pipe(x,f,f2) → f2(f(x)) xah_pipe(x,f,f2,f3) → f3(f2(f(x))) etc URL http://xahlee.info/js/js_function_chaining.html Created 2016 Version 2022-10-14 */ const xah_pipe = ((...xargs) => xargs.reduce((a, b) => b(a))); // ssss--------------------------------------------------- // test const fa = ((x) => (x + "a")); const fb = ((x) => (x + "b")); const fc = ((x) => (x + "c")); console.log(xah_pipe("0") === "0"); console.log(xah_pipe("0", fa) === "0a"); console.log(xah_pipe("0", fa, fb) === "0ab"); console.log(xah_pipe("0", fa, fb, fc) === "0abc");
JavaScript, Function
- JS: Define Function
- JS: Arrow Function
- JS: Function Parameters
- JS: arguments Object
- JS: Function Rest Parameters
- JS: Function Argument Default Value
- JS: Function Argument Destructure
- JS: Function Declaration vs Function Expression
- JS: Closure
- JS: Function Call, Apply, Bind
- JS: Functional Programing
- JS: Function Pipe 🚀
- JS: Function Object
- JS: Function Constructor
- JS: Function.prototype