Scala pattern matching option string
<p>I have an option of string called failureType. According to values of this String I have to decide what type of object I want to create. Something like - </p>

<pre><code>val failure: Option[FailureType] = failureType map (f =&gt; f.toLowerCase match {
          case "build" =&gt; FailureType.BuildFailure
          case "test" =&gt; FailureType.TestFailure
          case "service timeout" =&gt; FailureType.ServiceTimeout
          case "job timeout" =&gt; FailureType.JobTimeout
          case "work item timeout" =&gt; FailureType.WorkItemTimeout
        } )
</code></pre>

<p>My problem is I get Match Error if I give values other than "build", "test", "service timeout", "job timeout" or "work item timeout" to failureType. Which makes sense because I am not doing any default catching.  So my problem is how to do this default catching ? If I do </p>

<pre><code>case _ =&gt; None
</code></pre>

<p>At the end of other case statements, I would get error, because of course I am inside Map. My other option seem to be not using map at all and directly doing match - </p>

<pre><code>val failure: Option[FailureType] = failureType match {
          case Some("build") =&gt; FailureType.BuildFailure
          case Some("test") =&gt; FailureType.TestFailure
          case Some("service timeout") =&gt; FailureType.ServiceTimeout
          case Some("job timeout") =&gt; FailureType.JobTimeout
          case Some("work item timeout") =&gt; FailureType.WorkItemTimeout
          case _ =&gt; None
        }
</code></pre>

<p>But in this case I lose the ability to do case insensitive matching.</p>