maxWithOrNull method
Returns the first element having the largest value according to the
provided comparator
or null if there are no elements.
Implementation
E? maxWithOrNull(Comparator<E> comparator) {
if (isEmpty) return null;
final iterator = this.iterator..moveNext();
var maxElement = iterator.current;
while (iterator.moveNext()) {
final element = iterator.current;
if (comparator(maxElement, element) < 0) maxElement = element;
}
return maxElement;
}