Prelude API
    Preparing search index...

    Function union

    • Computes the union of two range sets, merging overlapping and adjacent ranges.

      When ranges overlap or are adjacent with equal values, they are merged into a single range. When ranges overlap with different values, the overlapping portion gets a merged value according to the value merge function, and non-overlapping portions are preserved.

      Type Parameters

      • K

        The type of range boundaries

      • V

        The type of range values

      Parameters

      • rangeSet: RangeSet<K, V>

        The first range set containing key/value operations and ranges

      • otherRangeSet: { ranges: Range.Range<K, V>[] }

        The second range set containing ranges to union with the first

      Returns RangeSet<K, V>

      A new range set containing the union of both input range sets

      const rs1 = { ranges: [Range.of(1, 3, 5)], key: Key.closed, value: Value.sum };
      const rs2 = { ranges: [Range.of(2, 4, 3)] };
      const result = union(rs1, rs2);
      // Result contains merged ranges with summed values where they overlap