Skip to content

Instantly share code, notes, and snippets.

@WagnerMoreira
Last active December 26, 2019 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WagnerMoreira/b5239ea63806fd749f4c80468313b587 to your computer and use it in GitHub Desktop.
Save WagnerMoreira/b5239ea63806fd749f4c80468313b587 to your computer and use it in GitHub Desktop.
Javascript Currying Functions Example
// regular version
let dragon = (name, size, element) =>
name + 'is a ' +
size + ' dragon that breathes ' +
element + '!';
//usage // usage dragon('zezinho', 'small', 'ice');
// currying version
let dragon =
name =>
size =>
element =>
name + 'is a ' +
size + ' dragon that breathes ' +
element + '!';
// usage dragon('zezinho')('small')('ice');
// The currying version only works if all 3 params are passed
// if not, the console it will just say it's a function and print the function
// we can also make something curryable using lodash _.curry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment