Created
June 27, 2016 05:14
-
-
Save stefanfrede/be458753a4b33e169945cb8b59639830 to your computer and use it in GitHub Desktop.
The B Combinator, or compose.
This file contains hidden or 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
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