Returns a function that performs functions composition from left to right.
💡
The pipe
function is equivalent to c(b(a(val)))
.
Related
Syntax
import { pipeFn } from '@opentf/std';
pipeFn(
...fns: Function[]
): (...args: unknown[]) => unknown
Examples
const transform = pipeFn(Math.pow, Math.abs);
transform(-2, 3); //=> 8
Try
Learn
Why we need function composition?
- The deep nesting of functions is hard to read.
- It eliminates temporary variables.
- Method chaining is limited, for Eg: await, yeild, etc.