I have `LiveData<List<User>>` loaded f...
# coroutines
k
I have
LiveData<List<User>>
loaded from firestore now i want to load `Appointment`s for each user from firestore, in end i want to create something like this
Map<User,Appointment>
. which
flow
operator can helps me in this situation, or flow is not best suited for this?
z
You could use flow for this, but I'm not sure you'd need to. Once you have your
List<User>
you can just do something like:
Copy code
users
  .map { user ->
    user to async { loadAppointments(user) }
  } // List<Pair<User, Deferred<Appointment>>>
  .toMap() // Map<User, Deferred<Appointment>>
  // This is an inline operator so it's allowed to make suspending calls if you're already in a suspend function.
  .mapValues { it.value.await() } // Map<User, Appointment>