@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UIntArray.maxBy( selector: (UInt) -> R ): UInt?
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> ULongArray.maxBy( selector: (ULong) -> R ): ULong?
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UByteArray.maxBy( selector: (UByte) -> R ): UByte?
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UShortArray.maxBy( selector: (UShort) -> R ): UShort?
Returns the first element yielding the largest value of the given function or null
if there are no elements.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val nameToAge = listOf("Alice" to 42, "Bob" to 28, "Carol" to 51)
val oldestPerson = nameToAge.maxBy { it.second }
println(oldestPerson) // (Carol, 51)
val emptyList = emptyList<Pair<String, Int>>()
val emptyMax = emptyList.maxBy { it.second }
println(emptyMax) // null
//sampleEnd
}
inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy( selector: (Entry<K, V>) -> R ): Entry<K, V>?
Returns the first entry yielding the largest value of the given function or null
if there are no entries.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val nameToAge = listOf("Alice" to 42, "Bob" to 28, "Carol" to 51)
val oldestPerson = nameToAge.maxBy { it.second }
println(oldestPerson) // (Carol, 51)
val emptyList = emptyList<Pair<String, Int>>()
val emptyMax = emptyList.maxBy { it.second }
println(emptyMax) // null
//sampleEnd
}
© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/max-by.html