something like this: `val nonOptional = optional ?...
# announcements
i
something like this:
val nonOptional = optional ?: Log.e("foo", "optional is not set").also { return }
s
maybe more like
Copy code
val nonOptional = optional ?: run {
  Log.e("foo", "optional is not set")
  return
}
i
awesome, thanks!
l
I fail to find this readable!
Perhaps you can use a delegate here, but I don't think this elvis operator + run + return is anywhere close to readable, even if it works
s
I feel like you’re maybe exaggerating how unreadable this is, but I’ll agree that it’s actually not the most idiomatic
really this should be replaced with smartcasting, but that’s predicated on the source property being a
val
and not being computed
and if it’s a var or computed value, you’ll need to cache the result of the access call and then compare against that
how you go about it is a bit contextual imo