Skip to content

Instantly share code, notes, and snippets.

@stefanfrede
Created June 27, 2016 05:14
Show Gist options
  • Save stefanfrede/be458753a4b33e169945cb8b59639830 to your computer and use it in GitHub Desktop.
Save stefanfrede/be458753a4b33e169945cb8b59639830 to your computer and use it in GitHub Desktop.
The B Combinator, or compose.
const compose = (a, b) =>
(c) => a(b(c))
// Given:
const addOne = (number) => number + 1;
const doubleOf = (number) => number * 2;
// Instead of:
const doubleOfAddOne = (number) => doubleOf(addOne(number));
// We could write:
const doubleOfAddOne = compose(doubleOf, addOne);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment