@staticmethod
def _union(intervals):
    """Unions sub-intervals of 'intervals' in-place.
        Assumes that 'intervals' sorted by first component of sub-element."""
    while len(intervals) > 0:
        prev = intervals.pop(0)
        if prev[0] == prev[1]:
            continue
        break
    else:
        return intervals
    for _ in range(len(intervals)):
        cur = intervals.pop(0)
        if cur[0] == cur[1]:
            continue
        if prev[1] < cur[0]:
            intervals.append(prev)
            prev = cur
        else:
            prev = prev[0], max(prev[1], cur[1])
    intervals.append(prev)
    return intervals
