Functional
compose

🧩 Performs right-to-left function composition.

Syntax

import { compose } from '@opentf/std';
 
compose(...funcs: Function[]): (val: any) => any;

Parameters

  • ...funcs: The functions to compose.

Returns

A new function that represents the composition of the input functions.

Examples

const add2 = (n) => n + 2;
const times3 = (n) => n * 3;
 
const add2ThenTimes3 = compose(times3, add2);
add2ThenTimes3(5); //=> 21 ( (5 + 2) * 3 )

Related

Try