I donβt know why this is not in the standard library, but you can easily pimp your library with an implicit class
implicit class MapFunctions[A, B](val map: Map[A, B]) extends AnyVal { def mapKeys[A1](f: A => A1): Map[A1, B] = map.map({ case (a, b) => (f(a), b) }) } val m = Map(1 -> "aaa", 2 -> "bbb") println(m.mapKeys(_ + 1))
source share