Sanctuary: What would be the equivalent to Ramda's lensPath + set?

Created on 29 Jan 2018  路  1Comment  路  Source: sanctuary-js/sanctuary

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

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidchambers picture davidchambers  路  8Comments

davidchambers picture davidchambers  路  8Comments

Siilwyn picture Siilwyn  路  5Comments

toolsh picture toolsh  路  6Comments

fnune picture fnune  路  3Comments