@ou-imdt/utils
Version:
Utility library for interactive media development
13 lines • 518 B
JavaScript
/**
* Composes multiple functions into a single function. Each function is called on the result of the
* preceding one, starting from the rightmost function.
* @param {...Function} functions - The functions to compose.
* @returns {Function} A composed function that represents the composition of input functions applied from right to left.
*/
export default function composeFunction(...functions) {
return (input) => {
return functions.reduceRight((acc, fn) => {
return fn(acc);
}, input);
};
};