minOfOrNull

inline fun <T> Array<out T>.minOfOrNull(selector: (T) -> Double): Double?(source)
inline fun ByteArray.minOfOrNull(selector: (Byte) -> Double): Double?(source)
inline fun ShortArray.minOfOrNull(selector: (Short) -> Double): Double?(source)
inline fun IntArray.minOfOrNull(selector: (Int) -> Double): Double?(source)
inline fun LongArray.minOfOrNull(selector: (Long) -> Double): Double?(source)
inline fun FloatArray.minOfOrNull(selector: (Float) -> Double): Double?(source)
inline fun DoubleArray.minOfOrNull(selector: (Double) -> Double): Double?(source)
inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Double): Double?(source)
inline fun CharArray.minOfOrNull(selector: (Char) -> Double): Double?(source)
inline fun <T> Array<out T>.minOfOrNull(selector: (T) -> Float): Float?(source)
inline fun ByteArray.minOfOrNull(selector: (Byte) -> Float): Float?(source)
inline fun ShortArray.minOfOrNull(selector: (Short) -> Float): Float?(source)
inline fun IntArray.minOfOrNull(selector: (Int) -> Float): Float?(source)
inline fun LongArray.minOfOrNull(selector: (Long) -> Float): Float?(source)
inline fun FloatArray.minOfOrNull(selector: (Float) -> Float): Float?(source)
inline fun DoubleArray.minOfOrNull(selector: (Double) -> Float): Float?(source)
inline fun BooleanArray.minOfOrNull(selector: (Boolean) -> Float): Float?(source)
inline fun CharArray.minOfOrNull(selector: (Char) -> Float): Float?(source)

Returns the smallest value among all values produced by selector function applied to each element in the array or null if the array is empty.

If any of values produced by selector function is NaN, the returned result is NaN.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   data class Rectangle(val width: Double, val height: Double) {
    val aspectRatio: Double get() = if (height != 0.0) width / height else Double.NaN
}

// The largest and smallest width-to-height ratios
val rectangles = listOf(
    Rectangle(15.0, 10.0),
    Rectangle(25.0, 20.0),
    Rectangle(40.0, 30.0),
)
println(rectangles.maxOf { it.aspectRatio }) // 1.5
println(rectangles.minOf { it.aspectRatio }) // 1.25

// Aspect ratio of a point (0.0 by 0.0) is NaN, hence the result is NaN
val rectanglesAndPoint = rectangles + Rectangle(0.0, 0.0)
println(rectanglesAndPoint.maxOf { it.aspectRatio }) // NaN
println(rectanglesAndPoint.minOf { it.aspectRatio }) // NaN

val emptyList = emptyList<Rectangle>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.aspectRatio } // will fail with NoSuchElementException
// emptyList.minOf { it.aspectRatio } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.aspectRatio }) // null
println(emptyList.minOfOrNull { it.aspectRatio }) // null 
   //sampleEnd
}

inline fun <T, R : Comparable<R>> Array<out T>.minOfOrNull(selector: (T) -> R): R?(source)

Returns the smallest value among all values produced by selector function applied to each element in the array or null if the array is empty.

If multiple elements produce the minimal value, this function returns the first of those values.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // The length of the longest and shortest names
val names = listOf("Alice", "Bob", "Carol")
println(names.maxOf { it.length }) // 5
println(names.minOf { it.length }) // 3

val emptyList = emptyList<String>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.length } // will fail with NoSuchElementException
// emptyList.minOf { it.length } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.length }) // null
println(emptyList.minOfOrNull { it.length }) // null 
   //sampleEnd
}

inline fun <R : Comparable<R>> ByteArray.minOfOrNull(selector: (Byte) -> R): R?(source)
inline fun <R : Comparable<R>> ShortArray.minOfOrNull(selector: (Short) -> R): R?(source)
inline fun <R : Comparable<R>> IntArray.minOfOrNull(selector: (Int) -> R): R?(source)
inline fun <R : Comparable<R>> LongArray.minOfOrNull(selector: (Long) -> R): R?(source)
inline fun <R : Comparable<R>> FloatArray.minOfOrNull(selector: (Float) -> R): R?(source)
inline fun <R : Comparable<R>> DoubleArray.minOfOrNull(selector: (Double) -> R): R?(source)
inline fun <R : Comparable<R>> BooleanArray.minOfOrNull(selector: (Boolean) -> R): R?(source)
inline fun <R : Comparable<R>> CharArray.minOfOrNull(selector: (Char) -> R): R?(source)

Returns the smallest value among all values produced by selector function applied to each element in the array or null if the array is empty.

If multiple elements produce the minimal value, this function returns the first of those values.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // The largest and smallest last digits in the array
val numbers = intArrayOf(13, 7, 22, 64)
println(numbers.maxOf { it % 10 }) // 7
println(numbers.minOf { it % 10 }) // 2

val emptyArray = intArrayOf()

// maxOf() and minOf() throw if the array is empty
// emptyArray.maxOf { it % 10 } // will fail with NoSuchElementException
// emptyArray.minOf { it % 10 } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the array is empty
println(emptyArray.maxOfOrNull { it % 10 }) // null
println(emptyArray.minOfOrNull { it % 10 }) // null 
   //sampleEnd
}

inline fun <T> Iterable<T>.minOfOrNull(selector: (T) -> Double): Double?(source)
inline fun <T> Iterable<T>.minOfOrNull(selector: (T) -> Float): Float?(source)

Returns the smallest value among all values produced by selector function applied to each element in the collection or null if the collection is empty.

If any of values produced by selector function is NaN, the returned result is NaN.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   data class Rectangle(val width: Double, val height: Double) {
    val aspectRatio: Double get() = if (height != 0.0) width / height else Double.NaN
}

// The largest and smallest width-to-height ratios
val rectangles = listOf(
    Rectangle(15.0, 10.0),
    Rectangle(25.0, 20.0),
    Rectangle(40.0, 30.0),
)
println(rectangles.maxOf { it.aspectRatio }) // 1.5
println(rectangles.minOf { it.aspectRatio }) // 1.25

// Aspect ratio of a point (0.0 by 0.0) is NaN, hence the result is NaN
val rectanglesAndPoint = rectangles + Rectangle(0.0, 0.0)
println(rectanglesAndPoint.maxOf { it.aspectRatio }) // NaN
println(rectanglesAndPoint.minOf { it.aspectRatio }) // NaN

val emptyList = emptyList<Rectangle>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.aspectRatio } // will fail with NoSuchElementException
// emptyList.minOf { it.aspectRatio } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.aspectRatio }) // null
println(emptyList.minOfOrNull { it.aspectRatio }) // null 
   //sampleEnd
}

inline fun <T, R : Comparable<R>> Iterable<T>.minOfOrNull(selector: (T) -> R): R?(source)

Returns the smallest value among all values produced by selector function applied to each element in the collection or null if the collection is empty.

If multiple elements produce the minimal value, this function returns the first of those values.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // The length of the longest and shortest names
val names = listOf("Alice", "Bob", "Carol")
println(names.maxOf { it.length }) // 5
println(names.minOf { it.length }) // 3

val emptyList = emptyList<String>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.length } // will fail with NoSuchElementException
// emptyList.minOf { it.length } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.length }) // null
println(emptyList.minOfOrNull { it.length }) // null 
   //sampleEnd
}

inline fun <K, V> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> Double): Double?(source)
inline fun <K, V> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> Float): Float?(source)

Returns the smallest value among all values produced by selector function applied to each entry in the map or null if the map is empty.

If any of values produced by selector function is NaN, the returned result is NaN.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   data class Rectangle(val width: Double, val height: Double) {
    val aspectRatio: Double get() = if (height != 0.0) width / height else Double.NaN
}

// The largest and smallest width-to-height ratios
val rectangles = listOf(
    Rectangle(15.0, 10.0),
    Rectangle(25.0, 20.0),
    Rectangle(40.0, 30.0),
)
println(rectangles.maxOf { it.aspectRatio }) // 1.5
println(rectangles.minOf { it.aspectRatio }) // 1.25

// Aspect ratio of a point (0.0 by 0.0) is NaN, hence the result is NaN
val rectanglesAndPoint = rectangles + Rectangle(0.0, 0.0)
println(rectanglesAndPoint.maxOf { it.aspectRatio }) // NaN
println(rectanglesAndPoint.minOf { it.aspectRatio }) // NaN

val emptyList = emptyList<Rectangle>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.aspectRatio } // will fail with NoSuchElementException
// emptyList.minOf { it.aspectRatio } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.aspectRatio }) // null
println(emptyList.minOfOrNull { it.aspectRatio }) // null 
   //sampleEnd
}

inline fun <K, V, R : Comparable<R>> Map<out K, V>.minOfOrNull(selector: (Map.Entry<K, V>) -> R): R?(source)

Returns the smallest value among all values produced by selector function applied to each entry in the map or null if the map is empty.

If multiple entries produce the minimal value, this function returns the first of those values.

Since Kotlin

1.4

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // The length of the longest and shortest names
val names = listOf("Alice", "Bob", "Carol")
println(names.maxOf { it.length }) // 5
println(names.minOf { it.length }) // 3

val emptyList = emptyList<String>()

// maxOf() and minOf() throw if the collection is empty
// emptyList.maxOf { it.length } // will fail with NoSuchElementException
// emptyList.minOf { it.length } // will fail with NoSuchElementException

// maxOfOrNull() and minOfOrNull() return null if the collection is empty
println(emptyList.maxOfOrNull { it.length }) // null
println(emptyList.minOfOrNull { it.length }) // null 
   //sampleEnd
}