title: How to create listBuffer in collect function
body: <p>I tought that List is enough but I need to add element to my list.</p>
  
  <p>I've tried to put this in ListBuffer constructor but without result.</p>
  
  <pre><code>  var leavesValues: ListBuffer[Double] =
      leaves
        .collect { case leaf: Leaf =&gt; leaf.value.toDouble }
        .toList
  </code></pre>
  
  <p>Later on I'm going to add value to my list so my expected output is mutable list.</p>
  
  <p><a href="https://stackoverflow.com/a/54035194/7990631">Solution of Raman Mishra</a> </p>
  
  <p>But what if I need to append single value to the end of leavesValues </p>
  
  <ol>
  <li>I can reverse but it's not good enough</li>
  <li><p>I can use ListBuffer like below but I believe that there is cleaner solution:</p>
  
  <pre><code>val leavesValues: ListBuffer[Double] = ListBuffer()
  leavesValues.appendAll(leaves
    .collect { case leaf: Leaf =&gt; leaf.value.toDouble }
    .toList)
  </code></pre></li>
  </ol>