title: Scala pattern matching on sequences other than Lists
body: <p>I have the following code which recursively operates on each element within a List</p>
  
  <pre><code>def doMatch(list: List[Int]): Unit = list match {
    case last :: Nil  =&gt; println("Final element.")
    case head :: tail =&gt; println("Recursing..."); doMatch(tail)
  }
  </code></pre>
  
  <p>Now, ignoring that this functionality is available through <em>filter()</em> and <em>foreach()</em>, this works just fine. However, if I try to change it to accept any <em>Seq[Int]</em>, I run into problems:</p>
  
  <ul>
  <li> Seq doesn't have ::, but it does have +:, which as I understand is basically the same thing. If I try to match on head +: tail however, the compiler complains 'error: not found: value +:'</li>
  <li> Nil is specific to List, and I'm not sure what to replace it with. I'm going to try Seq() if I ever get past the previous problem</li>
  </ul>
  
  <p>Here is how I think the code should look, except it doesn't work:</p>
  
  <pre><code>def doMatch(seq: Seq[Int]): Unit = seq match {
    case last +: Seq() =&gt; println("Final element.")
    case head +: tail  =&gt; println("Recursing..."); doMatch(tail)
  }
  </code></pre>
  
  <p>Edit: So many good answers! I'm accepting agilesteel's answer as his was the first that noted that :: isn't an operator in my example, but a case class and hence the difference.</p>