Is there anything like any() or false on a nullabl...
# getting-started
k
Is there anything like any() or false on a nullable List?
To avoid getting Boolean? back.
m
I would first of all avoid having nullable collection objects in the first place. I always default to returning an empty list instead of null. For your question, I would just do
list?.any() ?: false
m
an empty list is semantically different than a non-existent list. You probably want a nullable list to actually be empty instead. You can do either
Copy code
nullableList.orEmpty().any()
or
Copy code
nullableList?.any() ?: false
r
Another option would be:
Copy code
!nullableList.isNullOrEmpty()