NOTE: Object.assign will not work because it only makes a shallow copy.
Looking at the source code for Ramda.js
https://github.com/ramda/ramda/blob/v0.25.0/source/set.js
I'm looking to write a simple function to that will take an object, a path, and a value and return a new object. Ideally the new copy is as effecient as possible.
https://www.youtube.com/watch?v=n5REbbvRYqQ&feature=youtu.be&t=15m3s
Suppose I have an arbitrary object, which could be this
const obj = {
a: {
b: {
c: 1
}
}
e: 4
}
Example of the result produced by the function
const obj2 = func(obj,['a','b','c'],99)
console.log(obj2)
// {
// a: {
// b: {
// c: 99
// }
// }
// e: 4
//}
console.log(obj)
// {
// a: {
// b: {
// c: 1
// }
// }
// e: 4
//}
The ideal solution would create a new object efficiently as such: https://www.youtube.com/watch?v=n5REbbvRYqQ&feature=youtu.be&t=15m3s
Therefore if obj2.e = 5
then obj.e === 5
because only the func
created a copy of the branch being modified but kept all other references.