title: Pattern match empty ArrayBuffer
body: <p>Is there any special case class for representing an empty <code>ArrayBuffer</code> that can be used in pattern matching similar to <code>Nil</code> for lists?</p>
  
  <p>Also why this works:</p>
  
  <pre><code>scala&gt; collection.mutable.ArrayBuffer.empty == Nil
  res11: Boolean = true
  </code></pre>
  
  <p>While this does not:</p>
  
  <pre><code>scala&gt; collection.mutable.ArrayBuffer() match { case Nil =&gt; 1 }
  &lt;console&gt;:8: error: pattern type is incompatible with expected type;
   found   : scala.collection.immutable.Nil.type
   required: scala.collection.mutable.ArrayBuffer[Nothing]
  </code></pre>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>After giving it some thought I presume there is no such a case class. While existence of <code>Nil</code> is vital for <code>List</code> to work, no special structure of this kind is needed for arrays.  </p>
  
  <p>I've found a workaround for empty match check that might work in most cases:</p>
  
  <pre><code>collection.mutable.ArrayBuffer(2) match { 
    case collection.mutable.ArrayBuffer(v, _*) =&gt; v * 2
    case _ =&gt; 0 
  }
  </code></pre>
  
  <p>I first check if array has at least one element and otherwise it should be empty.
  Also as it turns out I could just use <code>ArrayBuffer.isEmpty</code> instead of pattern match.</p>