docstr: Merge two sequences of intervals into a single tuple of intervals.
  
  Any integer bounded by `x` or `y` is also bounded by the result.
  
  >>> union([(3, 10)], [(1, 2), (5, 17)])
  ((1, 17),)
docstr_tok: ["Merge","two","sequences","of","intervals","into","a","single","tuple","of","intervals",".","Any","integer","bounded","by","`","x","`","or","`","y","`","is","also","bounded","by","the","result",".",">",">",">","union","(","[","(","3",",","10",")","]",",","[","(","1",",","2",")",",","(","5",",","17",")","]",")","(","(","1",",","17",")",",",")"]
code: def union(self, other):
      """Merge two sequences of intervals into a single tuple of intervals.
  
      Any integer bounded by `x` or `y` is also bounded by the result.
  
      >>> union([(3, 10)], [(1, 2), (5, 17)])
      ((1, 17),)
      """
      assert isinstance(other, type(self))
      x = self.intervals
      y = other.intervals
      if not x:
          return IntervalSet((u, v) for u, v in y)
      if not y:
          return IntervalSet((u, v) for u, v in x)
      intervals = sorted(x + y, reverse=True)
      result = [intervals.pop()]
      while intervals:
          # 1. intervals is in descending order
          # 2. pop() takes from the RHS.
          # 3. (a, b) was popped 1st, then (u, v) was popped 2nd
          # 4. Therefore: a <= u
          # 5. We assume that u <= v and a <= b
          # 6. So we need to handle 2 cases of overlap, and one disjoint case
          #    |   u--v     |   u----v   |       u--v  |
          #    |   a----b   |   a--b     |  a--b       |
          u, v = intervals.pop()
          a, b = result[-1]
          if u <= b + 1:
              # Overlap cases
              result[-1] = (a, max(v, b))
          else:
              # Disjoint case
              result.append((u, v))
      return IntervalSet(result)
  
file_path: catboost/contrib/python/hypothesis/py3/hypothesis/internal/intervalsets.py
imports: from typing import Union
label_desc: Use image node_id 13 for calling the IntervalSet obj's underlying member method code with example usage: obj.union(other) and returns: IntervalSet, IntervalSet, IntervalSet