title: Is there a way to avoid using AnyPublisher/eraseToAnyPublisher all over the place?
body: <p>I'm just learning how to use Combine. I have experience with Rx (RxSwift and RxJava) and I'm noticing that it's quite similar.</p>
  
  <p>However, one thing that is quite different (and kind of annoying) is that the <code>Publisher</code> protocol doesn't use generics for its <code>Output</code> and <code>Failure</code> types; it uses associated types instead.</p>
  
  <p>What this means is that I can't specify a polymorphic <code>Publisher</code> type (such as <code>Publisher&lt;Int, Error&gt;</code>) and simply return any type that conforms to <code>Publisher</code> with those types. I need to use <code>AnyPublisher&lt;Int, Error&gt;</code> instead, and I am forced to include <code>eraseToAnyPublisher()</code> all over the place.</p>
  
  <p>If this is the only option, then I'll put up with it. However, I also recently learned about opaque types in Swift, and I'm wondering if I might be able to use them to get around this.</p>
  
  <p>Is there a way for me to have, say, a function that returns <code>some Publisher</code> and use specific types for <code>Output</code> and <code>Failure</code>?</p>
  
  <p>This seems like a perfect case for opaque types, but I can't figure out if there's a way for me to both use an opaque type and specify the associated types.</p>
  
  <p>I'm picturing something like this:</p>
  
  <pre class="lang-swift prettyprint-override"><code>func createPublisher() -&gt; some Publisher where Output = Int, Failure = Error {
      return Just(1)
  }
  </code></pre>