Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Modifying different spots of a datastructure in one go

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);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!