The documentation on Map.flatten states the following:
Converts this map of intersecting collections to a map formed by elements of these bypass collections.
I get a "workaround map". For example, it will be a map of lists. By this definition alone, a Map[Int, List[Int]] will qualify.
But what is a “map formed by elements of these workarounds”? It sounds simple, but it’s not easy for me to get it to work.
An example of the code given in the documentation ... well ... let's say, not applicable?
val xs = List( Set(1, 2, 3), Set(1, 2, 3) ).flatten // xs == List(1, 2, 3, 1, 2, 3) val ys = Set( List(1, 2, 3), List(3, 2, 1) ).flatten // ys == Set(1, 2, 3)
I tried several different things, but they give the same error. Here are some examples:
scala> val m = Map(List(1) -> List(1,2,3), List(2) -> List(4,5,6), List(3) -> List(7,8,9)) m: scala.collection.immutable.Map[List[Int],List[Int]] = Map(List(1) -> List(1, 2, 3), List(2) -> List(4, 5, 6), List(3) -> List(7, 8, 9)) scala> m.flatten <console>:9: error: No implicit view available from (List[Int], List[Int]) => scala.collection.GenTraversableOnce[B]. m.flatten ^ scala> val m = Map(1 -> List(1,2,3), 2 -> List(4,5,6), 4 -> List(7,8,9)) m: scala.collection.immutable.Map[Int,List[Int]] = Map(1 -> List(1, 2, 3), 2 -> List(4, 5, 6), 4 -> List(7, 8, 9)) scala> m.flatten <console>:9: error: No implicit view available from (Int, List[Int]) => scala.collection.GenTraversableOnce[B]. m.flatten ^
What am I missing?