So you don't have a noop. This is basically the sa...
# announcements
r
So you don't have a noop. This is basically the same as doing:
Copy code
val unwrapped = optional
if(unwrapped != null) { doSmth() }
else { doSmthElse() }
m
robin: I like this version more!
r
Yeah me too, actually... The elvis operator can make stuff obscure at times.
The
?.let
notation is only preferrable to an old-fashioned null check if the variable in question is non-local so you need an immutable local copy and you don't need an else-branch, imo.
a
@robin it is not the same. if
doSometh()
returns null,
doSmthElse()
will be called too
r
@Andreas Sinz You're correct. I was implying that doSometh() was just of Unit return type and therefore couldn't return null. If that's not the case you have to get around that.