Add Sequence.orEmpty #KT-16552 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-06-15 16:25:14 +09:00
committed by Ilya Gorbunov
parent 2ce0bca34e
commit c4b785de36
3 changed files with 28 additions and 0 deletions
@@ -47,6 +47,14 @@ private object EmptySequence : Sequence<Nothing>, DropTakeSequence<Nothing> {
override fun take(n: Int) = EmptySequence
}
/**
* Returns this sequence if it's not `null` and the empty sequence otherwise.
* @sample samples.collections.Sequences.Usage.sequenceOrEmpty
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>?.orEmpty(): Sequence<T> = this ?: emptySequence()
/**
* Returns a sequence of all elements from all sequences in this sequence.
*