between<T> function

bool Function(T) Function(T low, T hi) between<T>(
  1. Ord<T> O
)

Returns a function that checks if a value is within a given range.

Example:

void main() {
  // Create an Ord instance for integers
  Ord<int> ordInt = fromCompare((x, y) => x.compareTo(y));

  // Create a function to check if a value is between 1 and 10 (inclusive)
  bool Function(int) isBetween = between(ordInt)(1, 10);

  // Check if a value is between 1 and 10
  bool result = isBetween(5); // Output: true (5 is between 1 and 10)
}

Implementation

bool Function(T) Function(T low, T hi) between<T>(Ord<T> O) {
  return (T low, T hi) =>
      (T a) => O.compare(low, a) <= 0 && O.compare(a, hi) <= 0;
}