Created
August 30, 2019 06:59
-
-
Save Vterebenin/9da92e3e7eccbd72fbc2f9e54eb1d994 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
| function curry(callback, ...oldParameters) { | |
| return function(...parameters) { | |
| const nextParameters = [...oldParameters, ...parameters] | |
| if (nextParameters.length >= callback.length) { | |
| return callback(...nextParameters) | |
| } | |
| return curry(callback, ...nextParameters) | |
| } | |
| } | |
| const add = curry((a, b) => a + b) | |
| const increment = add(1) | |
| const decrement = add(-1) | |
| console.log(add(1, 2)) // 3 | |
| console.log(increment(1)) // 2 | |
| console.log(decrement(1)) // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment