Let's say I have this flow ```fun loadUsersByRegio...
# android
p
Let's say I have this flow
Copy code
fun loadUsersByRegion(regions: List<String>): Flow<List<User>>
I want to call fetchInfo on each item without nesting map....
Copy code
fun fetchInfo(user: User): Info
is there any better?
Copy code
.flatMapConcat { users ->
            flow {
                val usersInfo = users.map { user -> fetchInfo(user) }
                emit(usersInfo)
            }
        }
c
Why does loadUsersByRegion return a flow? It could suspend and return a List of Users
p
it is roomdb
g
Direct replacement would be:
Copy code
.flatMapConcat { users ->
 flowOf(users.map { fetchInfo(it) })
}
So at least there is no need to explicitly call
emit
But not sure about your usage of flatMapConcat for this, looks that I would prefer to use flatMapLatest, to cancel previus fetchInfo if update list of users already loaded, so it wouldn't create situation when a buch of updates of loadUsersByRegion() running one by one and slowdown actual emit of Info (because concat waits for every item) Still not very efficient, concidering that we request it again for any change in list of users, even if only one record is changes If fetchInfo is DB call, I feel that it must be done on DB level, if network, I would think about caching info for users instead