Is there a Map that takes a tuple as Key and provides methods to get views (as in Guava's Multimap) to "fix" one part of the key and get a Map that just takes the other part of the key?
This map should provide some methods like:
val ages = MagicMap[(String, String), Int]()
ages += ("Albert", "Einstein") -> 138
ages += ("Albert", "Schweitzer") -> 142
ages += ("Hermann", "Einstein") -> 170
val alberts: Map[String, Int] = ages.view1("Albert") // Map("Einstein" -> 138, "Schweitzer" -> 142)
val einsteins: Map[String, Int] = ages.view2("Einstein") // Map("Albert" -> 138, "Hermann" -> 170)
Due to performance, it is necessary to iterate over the submaps (i.e. alberts and einsteins), without iterating over the whole key set of the original map (ages). So, filter or groupBy do not help.
Also, using nested Maps (Map[String, Map[String, Int]]) is not possible, because they allow only filtering by one part of the key and not by the other.
Although immutable Maps would be okay, the most preferrable solution would be a mutable map that provides fully functional views, such that einsteins += "Eduard" -> 107 results in ages having one more entry ("Eduard", "Einstein") -> 107.