title: Passing Empty List of List Argument
body: <p>I worked on the "Pack Function" exercise from "Functional Programming Principles in Scala".</p>
  
  <blockquote>
    <p>Put consecutive duplicates into a <code>List[List[T]]</code>. </p>
  </blockquote>
  
  <p>Example</p>
  
  <pre><code>input: List("a", "a", "b", "b", "c", "a")
  output: List(List(a, a), List(b, b), List(c), List(a))
  </code></pre>
  
  <p>Given this function...</p>
  
  <pre><code>def pack[T](xs: List[T]): List[List[T]] = {
      def go[T](ys: List[T], acc: List[List[T]]) : List[List[T]] = ys match {
          case Nil =&gt; acc
          case x :: xs_ =&gt; val r: List[T] = ys.takeWhile(a =&gt; a == x)
                           go(ys.drop(r.length), acc :+ r)
      }
      go(xs, List(Nil).filter(_ != Nil)) // *** line in question ***
  }
  </code></pre>
  
  <p>Is there a better way to pass in a <code>List[List[T]]</code> where the inner list is empty?</p>
  
  <p>If I didn't have the <code>filter</code> there, the head of <code>pack(...)</code>'s result would be <code>List()</code>.</p>