A generic, immutable Interval over any ordered type
(Guava Range + DiscreteDomain model), plus built-in domains for the JS
primitives (number, integer, bigint, Date), and IntervalSet / IntervalMap
(Guava RangeSet / RangeMap) over any domain. Zero runtime dependencies.
Build a DISCRETE interval class over an ordered list of string labels (a “small enum”: sizes XS < S < M < L < XL, priority/log levels, …). Ordering is the list position, so adjacent labels merge and length() counts labels.
Bind a IntervalDomain to a concrete, new-able interval CLASS that extends Interval, so instances are instanceof Interval (and instanceof the bound class). The built-in classes (NumberInterval, DateInterval, …) are made this way; use it for your own domains.
Merge a bag of intervals into the minimal sorted set of disjoint pieces: overlapping or adjacent intervals are combined, empty ones are dropped, and the result is ordered by lower bound. Pass the domain the intervals use.
Parse [a,b), (-Infinity,5], ∅, etc. into an Interval<T> via domain.parse. The unbounded token is lenient — inf / infinity / ∞, any case, with an optional +/- sign — but toString() always emits the canonical ±Infinity. Empty text or ∅ gives the empty interval. Discrete domains are canonicalized, so (0,5] over the integers reads back as [1,5].
An immutable interval over an ordered type T, with set algebra (union/intersection/difference/…) decided entirely by an injected IntervalDomain. Build instances with the static Interval.of (or, more ergonomically, a domain-bound class from defineIntervalType); new Interval(...) is blocked because the constructor is protected. Every operation returns a fresh Interval — nothing mutates in place.
An immutable map from disjoint intervals of T to values V (Guava’s RangeMap). Each value of T maps to at most one V; IntervalMap.put overwrites whatever it overlaps, splitting the entries it cuts through, and IntervalMap.putCoalescing also merges the new entry with connected neighbours that hold an equal value. Every operation returns a new map.
An immutable set of values of T, stored as the minimal sorted list of disjoint, non-connected intervals (Guava’s RangeSet). Adding an interval coalesces it with every interval it overlaps or touches, so on a discrete domain [1,3] ∪ [4,6] is stored as [1,6], and on a continuous one [1,2) ∪ [2,3] as [1,3]. Every operation returns a new set.
The shape of a domain-bound interval CLASS produced by defineIntervalType: a new-able constructor plus the static factory methods. The explicit type is the public return type of defineIntervalType (not the local anonymous class) so .d.ts generation never has to synthesize an inline type literal for it.
Friendly constructor spec — explicit brackets, NO defaults. Give a side via its flat keys (start + startClose, both required together), or omit it entirely for an unbounded (±∞) side. Supplying start without startClose (or end without endClose) is a compile error.
Real numbers on the EXTENDED line — CONTINUOUS (no next). ±Infinity are real values, so a closed bracket on infinity is meaningful ([-Infinity,5] includes -∞). Only NaN is rejected (not comparable). Bound to a class as NumberInterval; also a handy base to spread into a custom domain.
Strings in lexicographic (UTF-16 code-unit) order — CONTINUOUS. Useful for keyspace / shard ranges, prefix scans, alphabetical buckets, and geohash spatial ranges (geohashes sort lexicographically). Code-unit order, NOT locale-aware. No measure (no natural distance between strings).