findExtent<E> static method
Computes an Extent from given data
by finding the minimum and maximum.
If E is Comparable, E.compareTo
is used for comparision. Otherwise,
comparator
argument is required.
Implementation
static Extent<E>? findExtent<E>(Iterable<E> data, {Comparator? comparator}) {
comparator ??= defaultComparator;
E? min;
E? max;
for (E d in data) {
if (d == null) continue;
if (max == null || comparator(d, max) > 0) max = d;
if (min == null || comparator(d, min) < 0) min = d;
}
if (min == null || max == null) {
return null;
}
return Extent<E>(min, max, comparator: comparator);
}