Last active
December 26, 2019 20:36
-
-
Save WagnerMoreira/b5239ea63806fd749f4c80468313b587 to your computer and use it in GitHub Desktop.
Javascript Currying Functions Example
This file contains 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
// 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