1

I want to find the best and lovely way to create matrix from map's like:

Map[String, List[String]]

In input we have List of Map's, and i want to aggregate it, if some keys doesnt' exist - we should put default value, for example - empty string.

For example:

val a = Map("one" -> List("1"), "two" -> List("2"))
val b = Map("one" -> List("11"), "two" -> List("22"), "three" -> List("3"))
val с = Map("four" -> List("44"))

And result that i want should be like:

Map(
      "one"   -> List("1", "11", ""),
      "two"   -> List("2", "22", ""), 
      "three" -> List("", "3", ""), 
      "four"  -> List("", "", "44")
   )

I don't like my solution - cause i create a lot of mutable List's and change their state on iteration.

I would be grateful if someone would tell me a more interesting solution, for example, without changing list's

Thanx!

aarexer
  • 523
  • 6
  • 20

0 Answers0