Say I am using a match expression to test a value that may or may not be in a Map object as follows:
map.get(key) match {
case Some(value) if (cond1(value)) => res1(value)
case Some(value) if (cond2(value)) => res2()
case None => res2()
case _ => // None of the above
}
As you can see I want to call the res2 in either case where I have a value for my key and it meets condition 2 or I have no value for key. Can anyone suggest a better construct that would avoid the duplicate calls to res2() in the sample above?
Thanks Des
* Sorry I realised that the code sample was not quite correct and have updated accordingly. I only want to call res2 in the case where the value for the key meets cond2 OR there is NO entry for key.