Last active
July 26, 2020 01:05
-
-
Save HichamBenjelloun/5734a1031e4cd4fa436c0f885e453748 to your computer and use it in GitHub Desktop.
Currying 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
/** | |
* Transforms a function of the form: | |
* fn = (p1, ..., pN) => f(p1, ...pN) | |
* to its curried form: | |
* curried = p1 => p2 => ... => pN => fn(p1, p2, ..., pN); | |
* | |
* @param fn | |
* @returns the curried form of fn | |
*/ | |
const curry = fn => | |
fn.length === 0 ? | |
fn() : | |
p => curry(fn.bind(null, p)); | |
export default curry; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can read more about currying in JavaScript here.