Gabriel Stefan
05/06/2025, 10:40 AM@Composable
fun MyComposable(input: Type?) {
if (input != null) {
XComposable(input)
} else {
YComposable()
}
}
vs
@Composable
fun MyComposable(input: Type?) {
input?.let {
XComposable(input)
} ?: YComposable()
}
My intuition is telling me that the first one is more idiomatic + it seems easier to understand at a glance but I can’t seem to find any references for that (so if you know of any I’d appreciate linking them)Stylianos Gakis
05/06/2025, 10:44 AMnull
Arne Jans
05/06/2025, 12:59 PM?.let {}
without any elvis operator and use if-else
if I need the null-case to be handled.
More often than not, to avoid unnecessary nesting, I would do
if (input == null) {
return
}
especially if there are several nullable parameters.Arne Jans
05/06/2025, 1:00 PM