findClosestTo method

T? findClosestTo(
  1. GeoCoords target
)

Find the element geographically closest to the target

Returns: The geographically closest T, or null if the list is empty

Implementation

T? findClosestTo(GeoCoords target) {
  return isEmpty
      ? null
      : fold(null, (p, c) {
          if (p == null) return c;
          var distP = target.distanceTo(p);
          var distC = target.distanceTo(c);
          return distP > distC ? c : p;
        });
}