Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active August 29, 2015 14:17
Show Gist options
  • Save fancellu/6f555fd31df13c560098 to your computer and use it in GitHub Desktop.
Save fancellu/6f555fd31df13c560098 to your computer and use it in GitHub Desktop.
Combines 2 maps of sequences. Have seen this asked a few times. This is a fairly concise solution.
def combine[K,V](map1:Map[K,Seq[V]], map2:Map[K,Seq[V]]) =
(map1.toList ++ map2.toList).groupBy(_._1).mapValues(_.map(_._2).flatten).map(identity)
@fancellu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment