ramda-adjunct
ramda-adjunct copied to clipboard
lensCopy
Is your feature request related to a problem? Please describe.
Function that take 2 lenses and some data, and copy data structure focused by lens1 to data structure focused by lens2. In fact, it's like copyKeys
(#516), but with lenses. For example, it allows to copy deep values.
Describe the solution you'd like
const lensCopy = (l1, l2, obj) => R.over(l2, R.view(l1), obj);
const a0 = lensPath(['a', 0]);
const bcd = lensPath(['b', 'c', 'd']);
lensCopy(lensPath(a0, bcd, { a: [42] }); //=> { a: [42], b: { c: { d: 42 } } }
Describe alternatives you've considered
--
Additional context
Based on #349, we can imagine adding lensCopyWhen
and lensCopyUnless
functions.
I like this.