Skip to content

Instantly share code, notes, and snippets.

@iofjuupasli
Created May 23, 2016 11:46
Show Gist options
  • Save iofjuupasli/dc251f17030d88603e71f86f3265c19d to your computer and use it in GitHub Desktop.
Save iofjuupasli/dc251f17030d88603e71f86f3265c19d to your computer and use it in GitHub Desktop.
myData.map(fixName);
function fixName(person) {
return Object.assign({}, person, {
name: person.name.replace(/John/g, "Ben")
});
}
// inline function
myData.map(function fixName(person) {
return Object.assign({}, person, {
name: person.name.replace(/John/g, "Ben")
});
});
// use R.replace instead String.prototype.replace
myData.map(function (person) {
return Object.assign({}, person, {
name: R.replace(/John/g, "Ben")(person.name)
});
});
// Use
// R.evolve({prop: fn})(item)
// instead
// Object.assign({}, item, {prop: fn(item['prop'])})
myData.map(function (person) {
return R.evolve({
name: R.replace(/John/g, "Ben")
})(person);
});
// f(x => u(x)) == f(u)
myData.map(R.evolve({
name: R.replace(/John/g, "Ben")
}));
// use R.map instead Array.prototype.map
R.map(R.evolve({
name: R.replace(/John/g, "Ben")
}))(myData);
// or separately
var fixName = R.replace(/John/g, "Ben");
var fixPersonName = R.evolve({ name: fixName });
var fixNames = R.map(fixPersonName);
var fixedData = fixNames(myData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment