operator - method

RangeCompactList operator -(
  1. Range otherRange
)
inherited

Return all the elements on the this range that is not present on the otherRange.

Getting a diff of ranges is good to identify specific changes on ranges.

Implementation

RangeCompactList operator -(Range otherRange) {
  final coll = RangeCompactList();

  // leading edge
  if (end <= otherRange.start) {
    coll.add(clone());
    return coll;
  }
  if (start < otherRange.start) {
    final diffStart = start;
    final diffEnd = otherRange.start;
    coll.add(Range(diffStart, diffEnd));
  }

  // trailing edge
  if (otherRange.end <= start) {
    coll.add(clone());
    return coll;
  }
  if (otherRange.end < end) {
    final diffStart = otherRange.end;
    final diffEnd = end;
    coll.add(Range(diffStart, diffEnd));
  }
  return coll;
}