Access case class parameter inside a map with default I have a map whose values are case classes, and I want to access one parameter of that case class with a default value if they map doesn't contain the provided key.

myMap.get(myKey).map(_.valueParam).getOrElse(defaultParam)


intellij-scala suggests that this is a "simplifiable operation on collection” -- is there a more idiomatic way to write this?

*

Edit/Answer: The alternative approach would be to use

myMap.get(myKey).fold(defaultParam)(valueParam)
Map has a getOrElse option:

myMap.getOrElse(myKey,defaultParameter).valueParameter