equalRange<T> function

Pair<int, int> equalRange<T>(
  1. List<T> list,
  2. T value, {
  3. int compare(
    1. T,
    2. T
    )?,
})

Returns a Pair containing the lowerBound and upperBound of value.

The list must be partitioned with respect to value (e.g., sorted). The returned range effectively bounds all elements equivalent to value.

Example:

final list = [10, 20, 30, 30, 40, 50];
final range = equalRange(list, 30); // Returns Pair(2, 4)

Implementation

Pair<int, int> equalRange<T>(
  List<T> list,
  T value, {
  int Function(T, T)? compare,
}) {
  return makePair(
    lowerBound(list, value, compare: compare),
    upperBound(list, value, compare: compare),
  );
}