Returns a function that performs functions composition from right to left.
💡
The compose
function is equivalent to a(b(c(val)))
.
Related
Syntax
import { composeFn } from '@opentf/std';
composeFn(
...fns: Function[]
): (...args: unknown[]) => unknown
Examples
const transform = composeFn(Math.abs, Math.pow);
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.