I have written the following helper
import * as L from 'partial.lenses';
const batchModify = (lenses, transform, datastructure) =>
lenses.reduce(
(acc, lens) => L.modify(lens, transform, acc),
datastructure
);
Which accomplishes what I want, but is also very wasteful because it produces intermediary data structures.
Example
Say I have this kind of object
{
foo: [10, 20, 30],
bar: {
bibi: [100, 200 , 300],
bobo: [1000, 2000 , 3000],
bubu: [10000, 20000 , 30000]
}
}
and I want to produce
{
foo: [11, 21, 31],
bar: {
bibi: [101, 201 , 301],
bobo: [1001, 2001 , 3001],
bubu: [10001, 20001 , 30001]
}
}
Pretend you can't just forge a fancy query. You need paths:
const foo = ['foo', L.elems];
const bibi = ['bar', 'bibi', L.elems];
const bobo = ['bar', 'bobo', L.elems];
const bubu = ['bar', 'bubu', L.elems];
What would be an alternative to the following?
batchModify([foo, bibi, bobo, bubu], x => x + 1, datastructure);