Currently, if the arguments to a function depend on a flag, then it could be written in the following way
if(isEnabled){ someFunction(a, b) } else{ someFunction(c, d) }
Can this be further simplified to someFunction( if(isEnabled) { (a, b) } else { (c, d) } )
?.
It should be working as is for single value since if
is an expression in kotlin. For multiple arguments it won’t work, unless you join them in pairs.
Adding this specifically to language grammar seems to be non-productive since it is a very narrow use-case.
2 Likes
You could do this, but is questionable whether it is an improvement:
::someFunction.let { if(isEnabled) it(a, b) else it(c, d) }
Alternatively using this instead of it:
::someFunction.run { if(isEnabled) invoke(a, b) else invoke(c, d) }
1 Like