Last active
September 18, 2017 02:17
-
-
Save devdilson/15b8e53c8bc4df65c7b7bd6d10749d06 to your computer and use it in GitHub Desktop.
A simple away of currying parameters into functions
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
| /* | |
| f -> the function | |
| The curried methods will be called with N args that are used into the function f. | |
| Tested in: https://stephengrider.github.io/JSPlaygrounds/ | |
| */ | |
| const curry = (f) => { | |
| const inner = (...args) => args.forEach(e => f(e)) || inner; | |
| return inner; | |
| } | |
| let result = 0; | |
| var sum = k => result += k; | |
| curry(sum)(1, 2, 3)(1)()(12)()()()()(1); | |
| result //20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment