One liner that uses breakOut to get an IntMap . It creates a map for the new collection using the custom factory constructor CanBuildFrom , which enables the breakOut call:
Map[Int, String](1 -> "").map(kv => kv)(breakOut[Map[Int, String], (Int, String), immutable.IntMap[String]])
In terms of performance, it's hard to say, but it creates a new IntMap , goes through all the bindings and adds them to IntMap . A handwritten iterator while (preceded by a pattern match to check if the original IntMap map is) may lead to slightly better performance.
source share