var exit: String = expensiveOperation
if (exit.contains(...)) exit = somethingElse
The key is I only wish to call
expensiveOperation
once since it consumes many clock cycles
If you don’t want to expose the other val
, do it inline:
val exit = {
val result = expensiveOperation
if (result.contains(...)) somethingElse
else result
}
or, if you like
val exit = expensiveOperation match {
case res if res.contains(...) => somethingElse
case res if res.contains(...) => somethingBetter
// ...
case res => res
}
a silly solution: just introduce another val.
val expected = expensiveOperation
val exit = if(expected.contains(...)) expected else something else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With