I was wondering... Why does `fun String?.orEmpty()...
# stdlib
l
I was wondering... Why does
fun String?.orEmpty(): String
was not defined for
CharSequence
? Is it a multiplatform constraint?
e
I wouldn't say that's true - many Android APIs take CharSequence, which can be annotated strings
but it's also pretty easy to write
?: ""
so it's not a huge missing gap
l
Of course, it's something I could define myself, and absolutely minor in the standard library development. But I would think that the inclusion of
orEmpty
for String alone could justify the equivalent for
CharSequence
, or at least something like
fun <C, R> C?.ifNull(defaultValue: () -> R): R where C : R
, for functional programming style.