Interval<T extends Comparable<Object?>>.open constructor

  1. @Possible({RangeError})
Interval<T extends Comparable<Object?>>.open(
  1. T min,
  2. T max
)

Creates an Interval with the open lower and upper bounds.

In other words, this interval excludes both min and max, i.e. { x | min < x < max }.

Contract

Throws a RangeError if min >= max.

Implementation

@Possible({RangeError})
Interval.open(T min, T max): min = (value: min, open: true), max = (value: max, open: true) {
  final value = min.compareTo(max);
  if (value < 0) {
    return;
  }

  if (value == 0) {
    throw RangeError('Invalid range: ($min...$max), minimum must be less than maximum. To represent an empty range, create an closed-open/open-closed range instead.');

  } else {
    throw RangeError("Invalid range: ($min...$max), minimum must be less than maximum. To fix, try swapping the values of 'min' and 'max'.");
  }
}