Created
August 25, 2021 16:38
-
-
Save smitroshin/7f3ccb9ae863f63a3b404c45410d57f3 to your computer and use it in GitHub Desktop.
Function composition - from left to right
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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