nkiesel
03/23/2022, 7:52 PMhasContent
and noContent
which are overloaded for strings, collections, maps, stringbuilders, ... and treat null
as "no content". While switching to Kotlin, we try to use as much of Kotlin stdlib methods as possible. Our noContent
easily translates to isNullOrEmpty
, but hasContent
results in !isNullOrEmpty
which is not pretty, especially if that is at the end of a chain because it separates the !
from the method: !foo.bar.baz.isNullOrEmpty()
. Is there a place for isNotNullOrEmpty()
in stdlib? (And yes, I realize that once we finished our journey from Java to Kotlin, we can drastically reduce the usage of nullable types and thus often use isNotEmpty()
. But that is still a long and windy road).
Update: I should have searched for this in YouTrack before asking: was rejected in KT-33689 because it claimed we could "shortly" write `foo.bar.baz.!isNullOrEmpty()`as described in KT-5351 . I guess that time will only come though after K2 went GA.jw
03/23/2022, 8:08 PMisNotNullOrEmpty
requires mental parenthesis which makes it open to interpretationjw
03/23/2022, 8:08 PM(!null) || empty
or !(null or empty)
? Different people will read it different ways.jw
03/23/2022, 8:11 PMnkiesel
03/23/2022, 8:12 PMhasContent
. But anyway, that proposal was already rejected 2 years ago.nkiesel
03/23/2022, 8:21 PMfirstNotNullOfOrNull
which could be parsed as `firstNot(NullOfOrNull)`or first(NotNullOfOrNull)
. Only the latter makes sense (to me), but thinking is required...jw
03/23/2022, 8:28 PM(firstNotNullOf) || null
therenkiesel
03/23/2022, 8:32 PMuli
03/23/2022, 9:09 PMfoo.bar.baz.isNullOrEmpty().not()
nkiesel
03/23/2022, 10:25 PM