Created
February 15, 2017 13:22
-
-
Save benedyktdryl/239ae338fbd17250577e8150b54ee0d7 to your computer and use it in GitHub Desktop.
Simple composition helper for FP in ES6.
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 = (...callbacks) => ( | |
(...args) => ( | |
callbacks.reduce((prev, callback) => ( | |
[callback(...prev)] | |
), args) | |
) | |
); | |
compose( | |
(x) => (x * 2), | |
(x) => (x * 3), | |
(x) => (x * 4) | |
)(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment