Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Created November 21, 2016 21:38
Show Gist options
  • Save dengjonathan/f0b21a463a0a5224fec92942fa982f97 to your computer and use it in GitHub Desktop.
Save dengjonathan/f0b21a463a0a5224fec92942fa982f97 to your computer and use it in GitHub Desktop.
ramda curry
//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 as an argument and
//returns the a copy with 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