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

348
Vistas
How to transform Flow<List<Flow<T>>> to Flow<List<T>>

I have database query that returns the list of indexes of objects for a certain day, i.e.:

getIndexesOfDay(day: Day): Flow<List<String>>

Now, I need to listen for details for each index, for instance:

getDetailsByIndex(index: String): Flow<Details>

So the question is: how can I accomplish this using Flows?

Two important constraints:

  1. Changes on the indexes should propagate to the final flow;
  2. Changes on any Details object should also update the flow.

What I have already tried:

getIndexesOfDay(todayDay)
          .map { indexes ->
              indexes?.map {
                      mIndex->
                  getDetailsByIndex(mIndex)
              }
          }

But it returns a Flow<List<Flow<Details>>> instead of the desired Flow<List<Details>>

Appreciate any help!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I haven't tested this, but I believe it should be possible using flatMapLatest() and combine():

getIndexesOfDay(todayDay)
    .flatMapLatest { indexes ->
        combine(indexes.map { getDetailsByIndex(it) }) { it.asList() }
    }

For each new list of indexes, it invokes getDetailsByIndex() multiple times to acquire a list of flows and then combines these flows into a single flow of details lists.

The drawback is that whenever indexes change, it throws away all Flow<Details> objects, even if an index existed in both old and new list of indexes. It would be probably better to create some kind of a cache of detail flows per each index.

over 4 years ago · Santiago Trujillo Denunciar
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