minWithOrNull method

E? minWithOrNull(
  1. Comparator<E> comparator
)

Returns the first element having the smallest value according to the provided comparator or null if there are no elements.

Implementation

E? minWithOrNull(Comparator<E> comparator) {
  if (isEmpty) return null;

  final iterator = this.iterator..moveNext();
  var minElement = iterator.current;

  for (final element in skip(1)) {
    if (comparator(minElement, element) > 0) minElement = element;
  }

  return minElement;
}