Last active
November 21, 2016 21:05
-
-
Save dengjonathan/219efacc4aeb6fb02b66de9e95cf168d to your computer and use it in GitHub Desktop.
Ramda curry
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
//Ramda | |
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 giveJobSmuggler = giveJob('smuggler') //=> returns a curried function that takes an object and gives its the property job = 'smuggler' | |
const solo = {name: 'Han'}; | |
const soloSmuggler = giveJobSmuggler(solo); //=> { name: 'Han', job: 'smuggler' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment