minByOrNull
inline fun <R : Comparable<R>> BooleanArray.minByOrNull(
selector: (Boolean) -> R
): Boolean?
(source)
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UIntArray.minByOrNull(
selector: (UInt) -> R
): UInt?
(source)
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> ULongArray.minByOrNull(
selector: (ULong) -> R
): ULong?
(source)
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UByteArray.minByOrNull(
selector: (UByte) -> R
): UByte?
(source)
@ExperimentalUnsignedTypes inline fun <R : Comparable<R>> UShortArray.minByOrNull(
selector: (UShort) -> R
): UShort?
(source)
Returns the first element yielding the smallest value of the given function or null
if there are no elements.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = listOf("abcd", "abc", "ab", "abcde")
val shortestString = list.minByOrNull { it.length }
println(shortestString) // ab
val emptyList = emptyList<String>()
val emptyMin = emptyList.minByOrNull { it.length }
println(emptyMin) // null
//sampleEnd
}
inline fun <K, V, R : Comparable<R>> Map<out K, V>.minByOrNull(
selector: (Entry<K, V>) -> R
): Entry<K, V>?
(source)
Returns the first entry yielding the smallest value of the given function or null
if there are no entries.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = listOf("abcd", "abc", "ab", "abcde")
val shortestString = list.minByOrNull { it.length }
println(shortestString) // ab
val emptyList = emptyList<String>()
val emptyMin = emptyList.minByOrNull { it.length }
println(emptyMin) // null
//sampleEnd
}