In general, I need a functional way to do one thing if the value was found on the Map and Do another thing if it was not found. Note that I'm not interested in the return value, but the action is complete.
Read more.
I have a service name map (friendly) to the PATH part of the URL (not just to remember). Here is the initialization.
val serviceMap = Map("read" -> "cryptic-read-path",
"save" -> "cryptic-save-path", "county" -> "cryptic-zip-code-to-county-service.");
All the alternatives that I know, lead to an if statement with the loaded part then, but simple 404 else. Here are some of them that I was thinking about
if (serviceMap.contains(service)) {
} else {
}
This is equivalent to the inverse predicate
if (!serviceMap.contains(key))
Both of the above approaches require me to check-receive-receive.
( )
serviceMap.get(service) match {
case _ : Option[String]=>
case _ =>
}
,
serviceMap.get(service).forEach {
Per , Option , , forEach .
, . , , ?
!