title: Swift Combine: How to create a single publisher from a list of publishers?
body: <p>Using Apple's new Combine framework I want to make multiple requests from each element in a list. Then I want a single result from a reduction of all the the responses. Basically I want to go from list of publishers to a single publisher that holds a list of responses.</p>
  
  <p>I've tried making a list of publishers, but I don't know how to reduce that list into a single publisher. And I've tried making a publisher containing a list but I can't flat map a list of publishers.</p>
  
  <p>Please look at the "createIngredients" function </p>
  
  <pre><code>func createIngredient(ingredient: Ingredient) -&gt; AnyPublisher&lt;CreateIngredientMutation.Data, Error&gt; {
      return apollo.performPub(mutation: CreateIngredientMutation(name: ingredient.name, optionalProduct: ingredient.productId, quantity: ingredient.quantity, unit: ingredient.unit))
              .eraseToAnyPublisher()
  }
  
  func createIngredients(ingredients: [Ingredient]) -&gt; AnyPublisher&lt;[CreateIngredientMutation.Data], Error&gt; {
      // first attempt
      let results = ingredients
              .map(createIngredient)
      // results = [AnyPublisher&lt;CreateIngredientMutation.Data, Error&gt;]
  
      // second attempt
      return Publishers.Just(ingredients)
              .eraseToAnyPublisher()
              .flatMap { (list: [Ingredient]) -&gt; Publisher&lt;[CreateIngredientMutation.Data], Error&gt; in
                  return list.map(createIngredient) // [AnyPublisher&lt;CreateIngredientMutation.Data, Error&gt;]
              }
  }
  </code></pre>
  
  <p>I'm not sure how to take an array of publishers and convert that to a publisher containing an array.</p>
  
  <p>Result value of type '[AnyPublisher]' does not conform to closure result type 'Publisher'</p>