char0n / ramda-adjunct

Ramda Adjunct is the most popular and most comprehensive set of functional utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
https://char0n.github.io/ramda-adjunct/
BSD 3-Clause "New" or "Revised" License
682 stars 86 forks source link

lensCopy #517

Open guillaumearm opened 6 years ago

guillaumearm commented 6 years ago

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.

char0n commented 6 years ago

I like this.