pablisco
09/01/2021, 8:33 AMFleshgrinder
09/01/2021, 8:40 AMsomeNullableString?.aFunction()
pablisco
09/01/2021, 8:43 AMimagine you can’t changein this exampleaFunction
pablisco
09/01/2021, 8:43 AMFleshgrinder
09/01/2021, 8:52 AMmcpiroman
09/01/2021, 9:02 AMpablisco
09/01/2021, 9:09 AMFleshgrinder
09/01/2021, 9:11 AMf(a, b)
- f(null, b)
- f(a, null)
- f(null, null)
Now mix it with a Java function where everything can be null, do we really want to short circuit out just because something is null which actually should be an error?
I think that asking users to handle this explicitly is safer. That said, I definitely see how this could cut down on boilerplate. 🙂ephemient
09/01/2021, 9:16 AMpablisco
09/01/2021, 9:17 AM// given
fun f(a: A, b: B): C = ...
inline fun f(a: A?, b: B?): C? =
when {
a == null -> null
b == null -> null
else -> f(a, b)
}
I can see problems with ambiguity though 🙃 If the compiler was able to introduce the short-circuit it would remove the ambiguity, potentially…pablisco
09/01/2021, 9:18 AM