maxWith
Returns the first element having the largest value according to the provided comparator.
@JvmName(name = "maxWithOrThrow")fun <T> Array<out T>.maxWith(comparator: Comparator<in T>): T(source)
data class Person(val name: String, val age: Int)
val people = arrayOf(
Person("Alice", 30),
Person("Bob", 25),
Person("Charlie", 35)
)
val oldest = people.maxWith(compareBy<Person> { it.age })
println("Oldest: ${oldest.name}, age ${oldest.age}")