Last active
November 21, 2016 23:58
-
-
Save dengjonathan/7a854a04aee3e293083a3ed2e83ff52c to your computer and use it in GitHub Desktop.
compose
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'); | |
// Example 1: f(g(x)) | |
const makeRen = obj => giveHero( | |
'Darth Vader', | |
giveName('Kylo') | |
); | |
// Example 2: using Ramda.compose | |
const makeRenCompose = R.compose(giveHero('Darth Vader'), giveName('Kylo')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment