Skip to content

Instantly share code, notes, and snippets.

@renesansz
Last active July 7, 2022 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renesansz/dd27153af3a52ac3647c621c82855f93 to your computer and use it in GitHub Desktop.
Save renesansz/dd27153af3a52ac3647c621c82855f93 to your computer and use it in GitHub Desktop.
A functional programming utility that composes functions from right to left.
/**
* A functional programming utility that composes functions from right to left.
*
* @param fns The functions to compose. Each function is expected to accept a single parameter.
* @returns The final function obtained by composing the given functions from right to left.
*/
export const compose = (...fns) =>
fns.reduceRight(
(prevFn, nextFn) =>
(...args) =>
nextFn(prevFn(...args)),
(value) => value
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment