Why is there a `String?.isNullOrBlank()` but there...
# stdlib
l
Why is there a
String?.isNullOrBlank()
but there is no
String?.isNotNullOrBlank()
while there is a
String.isBlank()
and
String.isNotBlank()
👆 1
a
If there was, shouldn't it really be called
String?.isNotNullButBlank()
l
I see.. then it should be
isNotNullNorBlank
Hard to negate that, huh? Probably why it doesnt exist?
a
yep and
!nullableStringVariable.isNullOrBlank()
does what (I assume) you are trying to do
s
strictly speaking, you could potentially instead do
if (maybeString?.isBlank() == false)
w
I often wish for a function that replaces
!isNullOrBlank()
, it’s pretty common requirement and negating manually is equally confusing to
isNotNullNorBlank
I’d definitely use
has[NonWhitespace]Content
or something similar
m
.neitherNullNorBlank()
n
in our Java projects we use overloaded (for String, List, Map, Array, ...)
hasContent
and
noContent
with an optional type-specific
trim
parameter (e.g. for String if
trim
is
true
then
hasContent
is
s != null && !s.trim().isEmpty
)