title: How to group by keys in a list
body: <p>I have a list in Scala that I want to group by a key and sum up the values of each key:</p>
  
  <pre><code>val l = List(("abc",1),("abc",2),("cbe",5),("cab",1))
  </code></pre>
  
  <p>I tried this code:</p>
  
  <pre><code>l.groupBy(identity).mapValues(_.sum) 
  </code></pre>
  
  <p>But got the following error:</p>
  
  <pre><code>error: type mismatch;
   found   : scala.collection.immutable.Map[(String, Int),Int]
   required: Seq[(String, Int)]
  </code></pre>