Say I have two maps:
val a = Map(1 -> "one", 2 -> "two", 3 -> "three")
val b = Map(1 -> "un", 2 -> "deux", 3 -> "trois")
I want to merge these maps by key, applying some function to collect the values (in this particular case I want to collect them into a seq, giving:
val c = Map(1 -> Seq("one", "un"), 2 -> Seq("two", "deux"), 3 -> Seq("three", "trois"))
It feels like there should be a nice, idiomatic way of doing this.
See Question&Answers more detail:os