Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Created November 16, 2016 04:22
Show Gist options
  • Save dengjonathan/041a991d335db9d3d8b30b2f4794e323 to your computer and use it in GitHub Desktop.
Save dengjonathan/041a991d335db9d3d8b30b2f4794e323 to your computer and use it in GitHub Desktop.
composition
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop});
const curry = (func, arg) => {
return (...args) => func(arg, ...args);
};
const giveName = curry(giveProp, 'name');
const giveJob = curry(giveProp, 'job');
const giveHero = curry(giveProp, 'hero');
const solo = giveJob(
'smuggler',
giveName('Han', {})
);
//{ name: 'Han', job: 'smuggler' }
const ren = giveHero(
'Darth Vader',
giveName('Kylo', {})
)
//{ name: 'Kylo', hero: 'Darth Vader' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment