Last active
November 21, 2016 21:35
-
-
Save dengjonathan/69f2c9273ebe155b32a34ac0d95106ee 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 R = require('ramda'); | |
const giveProp = (propName, prop, obj) => Object.assign({}, obj, {[propName]: prop}); | |
const givePropCurry = R.curry(giveProp); | |
const giveName = givePropCurry('name'); | |
const giveJob = givePropCurry('job'); | |
const giveHero = givePropCurry('hero'); | |
const makeSolo = R.compose(giveName('Han'), giveJob('smuggler')) //points-free style | |
const solo = makeSolo({movie: 'Star Wars'}); | |
//=>{ movie: 'Star Wars', job: 'smuggler', name: 'Han' } | |
const makeRen = R.compose(giveName('Kylo'), giveHero('Darth Vader')); | |
const ren = makeRen({movie: 'Star Wars'}); | |
//=>{ movie: 'Star Wars', hero: 'Darth Vader', name: 'Kylo' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment