maxWith method

KtMapEntry<K, V>? maxWith(
  1. Comparator<KtMapEntry<K, V>> comparator
)

Returns the first entry having the largest value according to the provided comparator or null if there are no entries.

Implementation

KtMapEntry<K, V>? maxWith(Comparator<KtMapEntry<K, V>> comparator) {
  final i = iterator();
  if (!i.hasNext()) return null;
  var max = i.next();
  while (i.hasNext()) {
    final e = i.next();
    if (comparator(max, e) < 0) {
      max = e;
    }
  }
  return max;
}