Skip to content

Instantly share code, notes, and snippets.

@gibbok
Created March 14, 2017 07:24
Show Gist options
  • Save gibbok/f1c6ab45b0e26c0f915fd339393b34cb to your computer and use it in GitHub Desktop.
Save gibbok/f1c6ab45b0e26c0f915fd339393b34cb to your computer and use it in GitHub Desktop.
GibboK - FP - Example of function composition in vanilla JavaScript
const compose = (f, ...fs) => x =>
f === undefined ? x : compose(...fs)(f(x))
const add = x => y => x + y
const mult = x => y => x * y
const main = compose(add(3), mult(4), add(5), mult(6))
console.log(main(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment