I've come up with the following implementation:
pagedUsersFlow.flatMapLatest {
flow {
it.map { user ->
userRemoteDS.getUserStatusFlow(user.id).onEach { status ->
emit(UserUI(user, status))
}.launchIn(coroutineScope)
}
}
}.collect { userUI ->
// use userUI
}
Update:
pagedUsersFlow.map {
it.map { user ->
val status = userRemoteDS.getUserStatusFlow(user.id).firstOrNull() ?: UserStatus("offline")
UserUI(user, status)
}
}.collect { pagingUI: PagingData<UserUI> ->
// ...
}
* Be the first to Make Comment