

def merge(iterables):
    'Merge multiple sorted inputs into a single sorted output.\n\n    Similar to sorted(itertools.chain(*iterables)) but returns a generator,\n    does not pull the data into memory all at once, and assumes that each of\n    the input streams is already sorted (smallest to largest).\n    '
    (_heappop, _heapreplace, _StopIteration) = (heappop, heapreplace, StopIteration)
    h = []
    h_append = h.append
    for (i, it) in enumerate(map(iter, iterables)):
        try:
            next = (it.next if hasattr(it, 'next') else it.__next__)
            h_append([next(), i, next])
        except _StopIteration:
            pass
    heapify(h)
    while 1:
        try:
            while 1:
                (v, i, next) = s = h[0]
                s[0] = next()
                (yield v)
                _heapreplace(h, s)
        except _StopIteration:
            _heappop(h)
            (yield v)
        except IndexError:
            return

dataset/ETHPy150Open bioinformed/vgraph/vgraph/intervals.py merge/original