firstOrNull

Returns the first element, or null if the sequence is empty.

fun <T> Sequence<T>.firstOrNull(): T?(source)
fun main() {
    val seq = sequenceOf("apple", "banana", "cherry")
    val first = seq.firstOrNull()
    println(first)          // prints "apple"

    val emptySeq = emptySequence<String>()
    val firstEmpty = emptySeq.firstOrNull()
    println(firstEmpty)     // prints "null"
}

Source