Marc Knaup
01/29/2019, 1:32 PMval <C : CharSequence> C.nonEmpty
get() = ifEmpty { null }
val <CollectionType : Collection<*>> CollectionType.nonEmpty
get() = ifEmpty { null }
val <Element> Array<Element>.nonEmpty
get() = ifEmpty { null }
val actualNonEmptyString = inputString?.nonEmpty ?: error("is required")
val actualNonEmptyList = inputList?.nonEmpty ?: error("is required")
ilya.gorbunov
01/29/2019, 5:43 PMnull
if it's empty? Then you can use .ifEmpty { null }
instead.Marc Knaup
01/29/2019, 7:13 PMilya.gorbunov
01/29/2019, 8:00 PMnotEmpty
extension property name doesn't look as clear as ifEmpty { null}
Marc Knaup
01/29/2019, 10:40 PMnonEmpty
is clearer than notEmpty
😁
nullIfEmpty
? 🤔
I really don't like the function call just for the null 😅aarjav
01/29/2019, 10:57 PMifEmpty
but a ifNullOrEmpty
could be nice. Then again, isNullOrEmpty
(and blank for strings) exists. inputString?.takeIf {!it.isNullOrEmpty()} ?: error("required")
aarjav
01/29/2019, 11:15 PM