distanceFnForType<T> function

DistanceFn distanceFnForType <T>(
  1. Type type
)

Returns a function that returns the distance between two given instances of type type.

Implementation

DistanceFn distanceFnForType<T>(Type type) {
  Map<Type, DistanceFn> distanceFnMap = {
    DateTime: (a, b) => a.difference(b).inMilliseconds.toDouble(),
    int: (a, b) => (a - b).toDouble(),
    double: (a, b) => (a - b).toDouble(),
  };

  if (distanceFnMap.containsKey(type)) return distanceFnMap[type];

  return (a, b) => a.compareTo(b).toDouble();
}