Skip to content

Instantly share code, notes, and snippets.

@bpinedah
Created December 10, 2018 21:14
Show Gist options
  • Save bpinedah/d37cb765b49adf3e99083f17a092448e to your computer and use it in GitHub Desktop.
Save bpinedah/d37cb765b49adf3e99083f17a092448e to your computer and use it in GitHub Desktop.
Currying article
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