How can I create a new map from two maps of maps so that the resulting map only includes matches where keys are the same and combines the internal maps.
Iterable[Map[String, Map[String,Float]]
Example:
val map1 = Iterable(Map(
1 -> Map(key1 -> val1),
2 -> Map(key2 -> val2),
3 -> Map(key3 -> val3)
))
val map2 = Iterable(Map(
1 -> Map(key11 -> val11),
3 -> Map(key33 -> val33),
4 -> Map(key44 -> val44),
5 -> Map(key55 -> val55)
))
I want the resulting map be as follows:
Map(
1 -> Map(key1 -> val1, key11 -> val11),
3 -> Map(key3 -> val3, key33 -> val33)
)
Update: I don’t really understand what your edit about
Iterables means, or the error in your comment, but here’s a complete working example withStrings andFloats:Update in response to your question below: it doesn’t make a lot of sense to have a list of maps, each containing a single mapping. You can very easily combine them into a single map using
reduceLeft:Now you have one big map of integers to maps of strings to floats, which you can plug into my answer above.