Is there anything like any() or false on a nullable List?
Kenneth
09/01/2022, 1:16 PM
To avoid getting Boolean? back.
m
marstran
09/01/2022, 1:24 PM
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
Michael de Kaste
09/01/2022, 1:25 PM
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