💾pipe(f, g, ...)
function composition
Last updated
Was this helpful?
function composition
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ function ⟩ higher-order ⟩ example ⟩ pipe()
function composition.
pipe(f, g, h)(x) === h(g(f(x)))
compose(f, g, h)(x) === f(g(h(x)))
replit ⟩ pipe(f1, f2, ...)
// ⭐ pipe:
// - pipe(f1, f2, f3 ...)(x,y,z ...) = ...f3(f2(f1(x,y,z ...)))
// ╰── funcs ───╯ ╰──args──╯
function pipe(...funcs) {
return function(...args) {
return funcs.slice(1).reduce(
(result,
example
const sum = (x, y) => x + y;
const square = x => x * x;
const add3 = x => x + 3;