title: Scala sum Map values
body: <p>I have a List</p>
  
  <pre><code>    val l : List[Map[String,Any]] = List(Map("a" -&gt; 1, "b" -&gt; 2.8), Map("a" -&gt; 3, "c" -&gt; 4), Map("c" -&gt; 5, "d" -&gt; "abc"))
  </code></pre>
  
  <p>and I used the following code to find the sum for the keys "a" (Int), "b" (Double) and "c" (Int). "d" is included as noise. </p>
  
  <pre><code>    l.map(n =&gt; n.mapValues( v =&gt; if (v.isInstanceOf[Number]) {v match {
      case x:Int =&gt; x.asInstanceOf[Int]
      case x:Double =&gt; x.asInstanceOf[Double]
      }} else 0)).foldLeft((0,0.0,0))((t, m) =&gt; (
  t._1 +  m.get("a").getOrElse(0), 
  t._2 + m.get("b").getOrElse(0.0), 
  t._3 + m.get("c").getOrElse(0)))
  </code></pre>
  
  <p>I expect the output would be (4, 2.8, 9) but instead I was trashed with </p>
  
  <pre><code>&lt;console&gt;:10: error: overloaded method value + with alternatives:
    (x: Int)Int &lt;and&gt;
    (x: Char)Int &lt;and&gt;
    (x: Short)Int &lt;and&gt;
    (x: Byte)Int
   cannot be applied to (AnyVal)
  </code></pre>
  
  <p>I think the exception was trying to tell me that '+' doesn't work with AnyVal. How do I get this to work to get my the result that I want? Thanks</p>