Best way to merge two maps and sum the values of same key?

The shortest answer I know of that uses only the standard library is

map1 ++ map2.map{ case (k,v) => k -> (v + map1.getOrElse(k,0)) }

Leave a Comment