title: In scala, how can I use pattern match to match a list with specified length?
body: <p>My codes looks like this:</p>
  
  <pre><code>1::2::Nil match {
    case 1::ts::Nil =&gt; "Starts with 1. More than one element"
    case 1::Nil =&gt; "Starts with 1. Only one element"
  }
  </code></pre>
  
  <p>I tried to use <code>1::ts::Nil</code> to match the List who starts with <code>1</code> and whose length is greater than 1. It workes well for 2-element list, however, this pattern doesn't work for <code>3-element list</code>, for example:</p>
  
  <pre><code>1::2::3::Nil match {
    case 1::ts::Nil =&gt; "Starts with 1. More than one element"
    case 1::Nil =&gt; "Starts with 1. Only one element"
  }
  </code></pre>
  
  <p>This won't work..Does anyone have ideas about this?</p>