Skip to content

Instantly share code, notes, and snippets.

@nelanka
Created September 30, 2014 18:49
Show Gist options
  • Save nelanka/7c8d563a581bd87c95b2 to your computer and use it in GitHub Desktop.
Save nelanka/7c8d563a581bd87c95b2 to your computer and use it in GitHub Desktop.
Merge Maps
def mergeMaps[A, B](map1: Map[A, Set[B]], map2: Map[A, Set[B]]): Map[A, Set[B]] = {
(map1.toSeq ++ map2.toSeq).groupBy(_._1).mapValues(_.map(_._2).toSet).mapValues(_.flatten)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment