Skip to content

Instantly share code, notes, and snippets.

@luijar
Last active September 26, 2015 20:53
Show Gist options
  • Save luijar/12b607b3a557c42f8f36 to your computer and use it in GitHub Desktop.
Save luijar/12b607b3a557c42f8f36 to your computer and use it in GitHub Desktop.
Ramda and Lenses
var ana = new Person('Ana', 'Gonzalez');
var firstnameLens = R.lensProp('firstname');
// read firtstname
R.view(firstnameLens, ana); //-> 'Ana'
// transform firstname to upper case
R.over(firstnameLens, R.toUpper, ana); //-> 'ANA'
// set firstname (creates a branch new object)
var olivia = R.set(firstnameLens, 'Olivia', ana)); //-> new Person('Olivia', 'Gonzalez')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment