title: Is there a better way to compare errors in Swift?
body: <p>I have this error:</p>
  
  <pre><code>public enum AuthenticationError: Error {
      case unknownError
      case canceledByUser
      case userOrPasswordMismatch
      case unableToExtractOneTimeCode
      case unableToExchangeOneTimeCodeForToken
      case credentialsUnavailable
      case expired
      case webRequestFailed(error: Error)
  }
  </code></pre>
  
  <p>I'd like to overload <code>==</code> to compare it but I find I need to repeat the code three ways:</p>
  
  <pre><code>public func == (lhs: Error, rhs: AuthenticationError) -&gt; Bool {
     return lhs._code == rhs._code &amp;&amp; lhs._domain == rhs._domain
  }
  
  public func == (lhs: AuthenticationError, rhs: Error) -&gt; Bool
  public func == (lhs: AuthenticationError, rhs: AuthenticationError) -&gt; Bool
  </code></pre>
  
  <p>An usage example is:</p>
  
  <pre><code>if let error = error, error == AuthenticationError.expired {
     // do something
  }
  </code></pre>
  
  <p>Is there a better way to do this (with generics) so I don't need to repeat similar code?</p>