# Access case class parameter inside a map with default [closed]

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)


## closed as off-topic by 200_successNov 7 '14 at 17:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

• Hi. Welcome to Code Review! We usually review more code than this. In particular, I would like to see where myMap is defined and loaded. As stands, this is more of a Stack Overflow question. Questions asking for help writing code are off-topic here. – Brythan Nov 7 '14 at 14:00
• Got it, sorry about that! – cohoz Nov 8 '14 at 16:37

myMap.getOrElse(myKey,defaultParameter).valueParameter

• You should rename defaultParameter since it is actually the container of the default parameter. – toto2 Nov 7 '14 at 21:09