min
Returns the smallest element in the array, or null if the array is empty. minBy and minWith variants allow custom comparison via a selector function or a Comparator.
Signatures
fun <T, D : Dimension> MultiArray<T, D>.min(): T?
where T : Number, T : Comparable<T>
inline fun <T, D : Dimension, R : Comparable<R>> MultiArray<T, D>.minBy(
selector: (T) -> R
): T?
fun <T, D : Dimension> MultiArray<T, D>.minWith(
comparator: Comparator<in T>
): T?
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Maps each element to a comparable value for ranking. |
|
| Custom comparator for ordering. |
Returns: The smallest element, or null if the array is empty.
Example
val a = mk.ndarray(mk[3, 1, 4, 1, 5])
a.min() // 1
a.minBy { -it } // 5 (smallest by negated value)
a.minWith(compareBy { it }) // 1
28 February 2026