Created
December 10, 2018 21:14
-
-
Save bpinedah/d37cb765b49adf3e99083f17a092448e to your computer and use it in GitHub Desktop.
Currying article
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
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
const filter = function(key, value){ | |
return function(i){ | |
return i[key] === value; | |
} | |
} | |
const applier = function(key, value){ | |
return function(i){ | |
i[key] = value; | |
} | |
} | |
const where = filter('name', 'Bruce'); | |
const apply = applier('lastname', 'Wayne'); | |
items.filter(where).map(apply); | |
console.log(items); | |
/* | |
[{ name: 'Bruce', lastname: 'Wayne' }, | |
{ name: 'Fabs' }, | |
{ name: 'Bruce', lastname: 'Wayne' }, | |
{ name: 'Gaby' }] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment