Created
November 16, 2016 04:22
-
-
Save dengjonathan/041a991d335db9d3d8b30b2f4794e323 to your computer and use it in GitHub Desktop.
composition
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
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