title: How to flatMap two Publishers with different Failure types in Combine
body: <p>I follow a pattern in my Rx code, I usually have an Observable trigger which I flatMap to create another Observable for a network request. A simplified example:</p>
  
  <pre><code>enum ViewModelError: Error {
    case bang
  }
  
  enum DataTaskError: Error {
    case bang
  }
  
  func viewModel(trigger: Observable&lt;Void&gt;,
                 dataTask: Observable&lt;Result&lt;SomeType, DataTaskError&gt;&gt;) -&gt; Observable&lt;Result&lt;AnotherType, ViewModelError&gt;&gt; {
    let apiResponse = trigger
      .flatMap { dataTask }
  }
  </code></pre>
  
  <p>The Combine equivalent I'm having some trouble with. I could use a Result as the Output type and use Never as the Failure type but that feels like a misuse of the API.</p>
  
  <pre><code>func viewModel(trigger: AnyPublisher&lt;Void, Never&gt;,
                 dataTask: AnyPublisher&lt;SomeType, DataTaskError&gt;) -&gt; AnyPublisher&lt;AnotherType, ViewModelError&gt; {
    let apiResponse = trigger
      .flatMap { dataTask }
  }
  </code></pre>
  
  <p>I get a compilation error:</p>
  
  <pre><code>Instance method 'flatMap(maxPublishers:_:)' requires the types 'Never' and 'DataTaskError' be equivalent
  </code></pre>
  
  <p>I could use mapError and cast both of the errors to Error, but I need a DataTaskError to be able to create my ViewModelError.</p>
  
  <p>This feels like it shouldn't be so difficult, and it seems like a fairly common use case. I'm likely just misunderstanding some fundamentals, a point in the right direction would be greatly appreciated.</p>