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)) }
More Related Contents:
- Scala: Merge map
- Confused with the for-comprehension to flatMap/Map transformation
- Scala: Why mapValues produces a view and is there any stable alternatives?
- Functional programming, Scala map and fold left [closed]
- How to convert scala List in to Map
- What are Scala context and view bounds?
- How to define and use a User-Defined Aggregate Function in Spark SQL?
- How to write to a file in Scala?
- Iteration over a sealed trait in Scala?
- Method parameters validation in Scala, with for comprehension and monads
- Where does the “flatmap that s***” idiomatic expression in Scala come from?
- Caused by: java.lang.NullPointerException at org.apache.spark.sql.Dataset
- About how to add a new column to an existing DataFrame with random values in Scala
- How to compare two dataframe and print columns that are different in scala
- Operate on neighbor elements in RDD in Spark
- Scala double definition (2 methods have the same type erasure)
- Renaming column names of a DataFrame in Spark Scala
- Difference between fold and foldLeft or foldRight?
- Scala macros: What is the difference between typed (aka typechecked) and untyped Trees
- Get TypeTag[A] from Class[A]
- In Scala, what exactly does ‘val a: A = _’ (underscore) mean?
- What are all the instances of syntactic sugar in Scala?
- Spark: long delay between jobs
- How to wait for several Futures?
- forall in Scala
- Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class
- assembly-merge-strategy issues using sbt-assembly
- How do I run an sbt main class from the shell as normal command-line program?
- How to create a Dataset of Maps?
- Spark ML VectorAssembler returns strange output