I have a mutable.Map (used in a method as a collection.Map[String, PathData] argument)
I wanted to find the average length of the keys, so I used the following sub expression (subsequently divided by the map size):
However, this gives the wrong answer (it is much too low). Converting it to a sequence first then gives the right answer:
Assuming that I’m not mutating the mutable map (which I’m not), then it is reasonable for these to return different answers, or is this just a bug?
This is an ammonite script, and I presume that I’m using the latest or very recent 2.13.X version.
println(pathMap.keys.toSeq.map(_.length).sum) println(pathMap.keys.map(_.length).sum) //prints 1307484 40665