Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda