Skip to content

Instantly share code, notes, and snippets.

@smitroshin
Created August 25, 2021 16:38
Show Gist options
  • Save smitroshin/7f3ccb9ae863f63a3b404c45410d57f3 to your computer and use it in GitHub Desktop.
Save smitroshin/7f3ccb9ae863f63a3b404c45410d57f3 to your computer and use it in GitHub Desktop.
Function composition - from left to right
/**
* Compose functions from left to right.
*
* Source: https://1loc.dev/#compose-functions-from-left-to-right
*
* Read more by googling: "js pipe", "js pipeline", "js compose from left to right".
*
* @param {...function} fns
* @returns {*}
*/
const pipe = (...fns) => (x) => fns.reduce((y, f) => f(y), x);
export default pipe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment