title: Use 'case' pattern matching to directly return result
body: <p>This is my code:</p>
  
  <pre><code>enum ServerResponse {
      case ok, error(Error), rawError(String), resend
  
      func isOk(response: ServerResponse) -&gt; Bool {
          case ServerResponse.ok = response
      }
  }
  </code></pre>
  
  <p>It doesn't compile with the following error:</p>
  
  <blockquote>
    <p>'case' label can only appear inside a 'switch' statement</p>
  </blockquote>
  
  <p>That's strange, since this is allowed:</p>
  
  <pre><code>func isOk(response: ServerResponse) -&gt; Bool {
      if case ServerResponse.ok = response {
          return true
      }
  
      return false
  }
  </code></pre>
  
  <p>But as we can see, it costs my extra lines of codes. I expect it to work since in Swift, only booleans are allowed. <a href="https://docs.swift.org/swift-book/ReferenceManual/Statements.html" rel="nofollow noreferrer">The docs</a> say: </p>
  
  <blockquote>
    <p>The value of any condition in an if statement <strong>must be of type Bool</strong> or
    a type bridged to Bool</p>
  </blockquote>
  
  <p>This means that this line should evaluate to a boolean, since above code compiles and the line of code is the condition inside an if statement:</p>
  
  <pre><code>case ServerResponse.ok = response
  </code></pre>
  
  <p>Why can't I use it to directly return a boolean inside a method (first code in the question)? Is there any oneliner that checks if a given enum property is a given enum case?</p>