maxBy

Common
JS
Native
1.7
@JvmName("maxByOrThrow") inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(
    selector: (T) -> R
): T

(source)
JVM
1.0
@DeprecatedSinceKotlin("1.4", "1.5", "1.6") inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(
    selector: (T) -> R
): T?

(source)
Deprecated: Use maxByOrNull instead.

Returns the first element yielding the largest value of the given function.

The operation is terminal.



fun main(args: Array<String>) {
//sampleStart
//Unresolved: samples.collections.Collections.Aggregates.maxBy
//sampleEnd
}

Exceptions

NoSuchElementException - if the sequence is empty.