Hey! I’m new with flow and I’ve been pondering how to implement the following data flow. My use case is that I’m using TMDB API with two endpoints: one to fetch a list of genres and second to fetch a list of movies per genre. This means that if the API returns N genres I have to make N requests to fetch the list of movies. My repository returns a flow of these objects, for example Flow<List<Genre> and Flow<List<Movie>>.
My question is, what would be a
flow way of “combining” these two streams, so that once the genres stream emits a value (it will only emit one value, all the genres), the genres would be looped over and movies would be queried for each, then those two combined.
If I were to do this without flow I’d do something like:
fun fetchData() {
val genresWithMovies: List<GenreWithMovies> = dataSource.queryGenres().map { genre ->
val movies = dataSource2.queryMovies(genre.id)
genre.movies = movies
genre
}
}
Any tips?