ifEmpty

Returns this char sequence if it's not empty or the result of calling defaultValue function if the char sequence is empty.

inline fun <C : CharSequence, R, R> C.ifEmpty(defaultValue: () -> R): R(source)
fun main() {
    val nonEmpty = "Kotlin".ifEmpty { "Default" }
    val empty = "".ifEmpty { "Default" }

    println(nonEmpty) // Kotlin
    println(empty)    // Default
}

Source