Hi,
I observed a difference in behavior with the following piece of code in Scala 2.12 vs Scala 2.13:
object Solution {
def groupAnagrams(strs: Array[String]): List[List[String]] = {
val groups = strs.groupBy(str => str.groupBy(identity).mapValues(_.length))
groups.map(_._2.toList).toList
}
def main(args: Array[String]): Unit = {
println(groupAnagrams(Array("eat","tea","tan","ate","nat","bat")))
}
}
Here the creation of groups use a Map as the key, this produces the following output in Scala 2.12.15:
List(List(eat, tea, ate), List(tan, nat), List(bat))
and the following output in Scala 2.13.7:
List(List(ate), List(tea), List(eat), List(bat), List(nat), List(tan))
I assume this is due to the MapView that is returned by the mapValues function.
Just wanted to confirm if this behavior is expected.
Thanks,
Krishna Rajendram Bashyam.