def union(record_list, min_distance=0, interval_func=attrgetter('start', 'stop')):
    n = len(record_list)
    start = stop = 0
    records = []

    for i, rec in iter_merge(record_list, key=interval_func):
        rec_start, rec_stop = interval_func(rec)

        if not records or min_distance <= rec_start - stop:
            if records:
                yield start, stop, demultiplex_records(n, records)
                records = []
            start, stop = rec_start, rec_stop

        assert rec_start >= start
        records.append((i, rec))
        stop = max(stop, rec_stop)

    if records:
        yield start, stop, demultiplex_records(n, records)
>>> from operator import itemgetter
dataset/ETHPy150Open bioinformed/vgraph/vgraph/intervals.py/union