minWithOrNull
Returns the first element having the smallest value according to the provided comparator or null if there are no elements.
fun <T> Sequence<T>.minWithOrNull(comparator: Comparator<in T>): T?(source)
data class Person(val name: String, val age: Int)
val people = sequenceOf(
Person("Alice", 30),
Person("Bob", 25),
Person("Charlie", 35)
)
val youngest = people.minWithOrNull(compareBy<Person> { it.age })
println(youngest?.name) // Output: Bob