You need to check `categories != null`. The compil...
# announcements
m
You need to check
categories != null
. The compiler cannot infer that it's not null from the
.orEmpty().isEmpty()
call.
👍 1
m
it have two thoughts about this case. and yes - first was that i want too much from compiler. but second - I miss something tnx
this one a bit verbose but also clear for compiler
m
Yes, because you capture the result of the
orEmpty
call with the
with
function. The receiver inside
with
is non-null.
In your first example, you throw away the result of
categories.orEmpty()
. You could do this to fix it:
Copy code
val nonNullCategories = categories.orEmpty()
if (nonNullCategories.isEmpty()) {
    0
} else { 
    nonNullCategories.map {
        ...
    }
}