You can use for-comprehensions to work with Option
but you can't use it for objects that don't have at least one defined foreach
, map
or flatMap
. In your case, if params
is returning options then...
for(
input1 <- params get "input1"
input2 <- params get "input2"
){
//do stuff
}
Wherein this will not run if both input
and input2
are not None
.
If you don't want to short circuit the control logic and you want there to be sane defaults for Option
returns, then a better way is just to do
myFunction(params getOrElse ("input1", "default1"), params getOrElse ("input2", 42))
where you're explicitly providing the defaults and passing them into a function call.