maxOfWith

inline fun <T, R> Array<out T>.maxOfWith(comparator: Comparator<in R>, selector: (T) -> R): R(source)

Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the array.

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

Since Kotlin

1.4

Throws

if the array is empty.

Samples


inline fun <R> ByteArray.maxOfWith(comparator: Comparator<in R>, selector: (Byte) -> R): R(source)
inline fun <R> ShortArray.maxOfWith(comparator: Comparator<in R>, selector: (Short) -> R): R(source)
inline fun <R> IntArray.maxOfWith(comparator: Comparator<in R>, selector: (Int) -> R): R(source)
inline fun <R> LongArray.maxOfWith(comparator: Comparator<in R>, selector: (Long) -> R): R(source)
inline fun <R> FloatArray.maxOfWith(comparator: Comparator<in R>, selector: (Float) -> R): R(source)
inline fun <R> DoubleArray.maxOfWith(comparator: Comparator<in R>, selector: (Double) -> R): R(source)
inline fun <R> BooleanArray.maxOfWith(comparator: Comparator<in R>, selector: (Boolean) -> R): R(source)
inline fun <R> CharArray.maxOfWith(comparator: Comparator<in R>, selector: (Char) -> R): R(source)
inline fun <R> UIntArray.maxOfWith(comparator: Comparator<in R>, selector: (UInt) -> R): R(source)
inline fun <R> ULongArray.maxOfWith(comparator: Comparator<in R>, selector: (ULong) -> R): R(source)
inline fun <R> UByteArray.maxOfWith(comparator: Comparator<in R>, selector: (UByte) -> R): R(source)
inline fun <R> UShortArray.maxOfWith(comparator: Comparator<in R>, selector: (UShort) -> R): R(source)

Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the array.

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

Since Kotlin

1.4

Throws

if the array is empty.

Samples


inline fun <T, R> Iterable<T>.maxOfWith(comparator: Comparator<in R>, selector: (T) -> R): R(source)

Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection.

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

Since Kotlin

1.4

Throws

if the collection is empty.

Samples


inline fun <K, V, R> Map<out K, V>.maxOfWith(comparator: Comparator<in R>, selector: (Map.Entry<K, V>) -> R): R(source)

Returns the largest value according to the provided comparator among all values produced by selector function applied to each entry in the map.

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

Since Kotlin

1.4

Throws

if the map is empty.

Samples