title: The map does not reset the value of the key
body: <p>I wrote the function to count the the occurrence of each char in the string, for example, "aadb  a", it should return a->3, d->1, b->1, the map size should be 3, but now it is wrong</p>
  
  <p>Below is the my code: may  I know the problem?</p>
  
  <pre><code>def checkPalindrome(str:String): Int={
     str.foldLeft(HashMap.empty[Char, Int]){(map, char)=&gt; (char) match{
       case ' '=&gt;map
       case _ =&gt;  map+(char -&gt; (map.getOrElse(char, 0) + 1))
     }
     }.size
   }
  </code></pre>