ifEmpty (original) (raw)
Returns a sequence that iterates through the elements either of this sequence or, if this sequence turns out to be empty, of the sequence returned by defaultValue function.
Since Kotlin
1.3
Samples
import kotlin.test.*
fun main() {
//sampleStart
val empty = emptySequence<Int>()
val emptyOrDefault = empty.ifEmpty { sequenceOf("default") }
println(emptyOrDefault.toList()) // [default]
val nonEmpty = sequenceOf("value")
val nonEmptyOrDefault = nonEmpty.ifEmpty { sequenceOf("default") }
println(nonEmptyOrDefault.toList()) // [value]
//sampleEnd
}