title: Chaining swift combine publishers and receiving each result
body: <p>In the example below, I’m making a network request to load different movie genres, then using that to load all the movies. The sink only returns the movie results. How could I receive both the genres and movies?</p>
  <pre><code>struct Genre: Codable, Identifiable{
      let id: Int
      let name: String
      var movies: [Movie]?
  }
  
  struct Movie: Codable, Hashable, Identifiable {
      let title: String
      let id: Int
      let posterPath: String?
      let backdropPath : String?
      var tagline: String?
  }
  
  loadGenres() is AnyPublisher&lt;[Genre], Error&gt; 
  fetchMoviesIn() is AnyPublisher&lt;[Movie], Error&gt;
  
  class GenresViewModel: ObservableObject{
      @Published var genres = [Genre]()
      @Published var movies = [Movie]()
      var requests = Set&lt;AnyCancellable&gt;()
      
      init(){
          NetworkManager.shared.loadGenres()
              .flatMap{ genres in
                  genres.publisher.flatMap{ genre in
                      NetworkManager.shared.fetchMoviesIn(genre)
                  }
              }
              .collect()
              .retry(1)
              .receive(on: DispatchQueue.main)
              .sink(receiveCompletion: { completion in
                  switch completion{
                  case .finished:
                      print(&quot;Finished loading all movies in every genre&quot;)
                  case .failure(let error):
                      print(&quot;Error: \(error)&quot;)
                  }
              }, receiveValue: { [self] values in
                  let allMovies = values.joined()
                  self.movies = allMovies.map{$0}
              })
              .store(in: &amp;self.requests)
      }
  }
  </code></pre>