Skip to content

Instantly share code, notes, and snippets.

@AkimaLunar
Created March 9, 2018 19:44
Show Gist options
  • Save AkimaLunar/b2316c8097df7cf6954225807e2827b9 to your computer and use it in GitHub Desktop.
Save AkimaLunar/b2316c8097df7cf6954225807e2827b9 to your computer and use it in GitHub Desktop.
Compose takes in functions as arguments and returns a single function
const compose = (...fns) => // 1. the spread operator torns function arguments into an array fns
(arg) => // 2. a function is then returned that expects one argument arg
fns.reduce( // 3. Reducing the fins with arg as the initial value
(composed, f) => f(composed), // 4. Each function is called with the result of the previous functions
arg // 3.arg is the initial value
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment