maxWithOrNull
Returns the first element having the largest value according to the provided comparator or null if there are no elements.
fun <T> Sequence<T>.maxWithOrNull(comparator: Comparator<in T>): T?(source)
val fruits = listOf("apple", "banana", "cherry")
val longestFruit = fruits.asSequence()
.maxWithOrNull(compareBy<String> { it.length })
println(longestFruit) // Output: banana