Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What would be the equivalent to Ramda's lensPath + set? #482

Closed
babakness opened this issue Jan 29, 2018 · 1 comment
Closed

What would be the equivalent to Ramda's lensPath + set? #482

babakness opened this issue Jan 29, 2018 · 1 comment

Comments

@babakness
Copy link

babakness commented Jan 29, 2018

What would be the equivalent here to Ramda's lensPath and set functionality

const obj = {
  a: {
    b: {
      c: 1
     }
  },
  d: {
    e: 2
  }
}
const obj2 = R.set(R.lensPath(['a','b','c'] ),99,obj)

// now let do bad things and mutate
obj.d.e = 99
console.log(obj2)
// ... e: 99 ...

It seems that only the modified path is updated, other branches of the object are left referencing nodes as before. I imagine this is for efficiency purposes, for example, illustrated in this video--only the updated node is copied.

https://youtu.be/n5REbbvRYqQ?t=15m2s

@davidchambers
Copy link
Member

Sanctuary will one day provide S.view, S.over, S.set, and at least one function for defining lenses (#177). This was not a high priority for me until I found myself making heavy use of lenses in a project last week, and added Ramda as a dependency just to use the handful of lens-related functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants