Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda