Skip to content

compose

Summary

Performs a right-to-left function composition.

Description

Given a list of functions returns a new function that takes any number of parameters and applies the rightmost function to them, the result of which is fed into the second rightmost function, etc. Returns the return value of the leftmost function.

Examples

1
2
3
const answer = compose(inc, inc, add);
answer(30, 10);
//=> 42

Parameters

Name Type Description
fn function

Return

function