ramda-adjunct icon indicating copy to clipboard operation
ramda-adjunct copied to clipboard

lensCopy

Open guillaumearm opened this issue 6 years ago • 1 comments

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.

guillaumearm avatar Apr 25 '18 09:04 guillaumearm

I like this.

char0n avatar May 30 '18 20:05 char0n