union method

ByteRange union(
  1. ByteRange other
)

Minimal union covering this and other. Adjacent or overlapping ranges are merged; disjoint non-adjacent ranges return the covering span.

Implementation

ByteRange union(ByteRange other) {
  if (!intersects(other) && end != other.start && other.end != start) {
    // For non-overlapping non-adjacent ranges, return the minimal covering range
    final s = start < other.start ? start : other.start;
    final e = end > other.end ? end : other.end;
    return ByteRange(s, e);
  }
  // Merge overlapping/adjacent
  final s = start < other.start ? start : other.start;
  final e = end > other.end ? end : other.end;
  return ByteRange(s, e);
}