Created
November 4, 2018 02:21
-
-
Save haru01/b1d90e7790cccbce8ea65dddc72e5ed1 to your computer and use it in GitHub Desktop.
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
| inc = (n) => n + 1 | |
| inc(2) | |
| square = (n) => n * n | |
| [1,2,3].map(inc) // [ 2, 3, 4 ] | |
| [1,2,3].map(square) // [ 1, 4, 9 ] | |
| compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x); | |
| incSquare = compose(inc, square) | |
| incSquare(3) // 10 | |
| pipe = (...fns) => x => fns.reduce((v, f) => f(v), x) | |
| incAndThenSquare = pipe(inc, square) | |
| incAndThenSquare(3) // 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment