inline fun <A>Collection<A>?.isNullOrEmpty() = this == null || this.isEmpty()
inline fun <A>Collection<A>?.isNotNullOrEmpty() = this != null && this.isNotEmpty()
The problem with that function is that, currently, you cannot take advantage of smart cast to avoid the need to use safe calls (?.), so depending on the case, it may not make much sense to use it.
Great idea! Default function should be in standard library.
But still, I wish Kotlin will treat null as false where a boolean is needed, just like Go does.
I am also in disfavor of seeing true/false literals in conditional expressions
To me, list?.isEmpty() ?: true is much more readable than list?isEmpty() != false
It’s the double negation that irks me. Reading across you are in the flow of a nullable expression, and suddenly get twisted into a boolean expression of equivalence with a boolean literal where you have to manually work out the understanding of what happens to null instead of just reading the flow of null naturally.
fun Boolean?.isNullOrFalse() = this == null || this == false
fun Boolean?.isNullOrTrue() = this == null || this == true
fun Boolean?.isNotNullAndTrue() = this != null && this
fun Boolean?.isNotNullAndFalse() = this != null && !this