Skip to content

Instantly share code, notes, and snippets.

@HichamBenjelloun
Last active July 26, 2020 01:05
Show Gist options
  • Save HichamBenjelloun/5734a1031e4cd4fa436c0f885e453748 to your computer and use it in GitHub Desktop.
Save HichamBenjelloun/5734a1031e4cd4fa436c0f885e453748 to your computer and use it in GitHub Desktop.
Currying functions
/**
* 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;
@HichamBenjelloun
Copy link
Author

You can read more about currying in JavaScript here.

@HichamBenjelloun
Copy link
Author

Pour en savoir plus sur la curryfication en JavaScript, vous pouvez lire cet article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment