While dealing with Option
in Scala what are the things I should be considering to decide whether to map or patten match? For example, if I have Option[MyClass]
, I can deal with it the following ways:
def getList(myOptionInstance: Option[MyClass]): List[String] =
myOptionInstance map (...) getOrElse(List.empty[String])
or
def getList(myOptionInstance: Option[MyClass]): List[String] = myOptionInstance match {
case Some(mySomeInstance) => .....
case None => List.empty[String]
}
When will I choose one over the other?