Doing `nullable?.let { list + it } ?: list`
# announcements
l
Doing
nullable?.let { list + it } ?: list
s
I mean, you could do
nullable?.let(list::add)
👍 1
or, keep it simple w/ an
if (nullable != null)
assuming mutablelist
are you reassigning or building a new read-only list or
d
Seems like a good place for a guard case if (nullable == null) return The other stuff seems to only needlessly complicate things.
l
Those are better
I guess sometimes we go for the most complicated version 😅
d
list + (nullable ?: listOf())
r
@David Glasser That won't work unless
nullable
is a list.