1 from heapq import heapify, heapreplace, heappop
2
4 __slots__ = ["head", "iter"]
5
9
11 try:
12 self.head = self.iter.next()
13 except StopIteration:
14 self.head = None
15
18
20 """
21 Takes a number of sorted iterables, and inteclass them, suppressing
22 doublons.
23 """
24 h = [ _IterHead(iter(i)) for i in iterables ]
25 h = [ ih for ih in h if ih.head is not None ]
26 heapify(h)
27 prev = None
28
29 while h:
30 ih = h[0]
31 ihh = ih.head
32 if prev is None or ihh != prev:
33 yield ihh
34 prev = ihh
35 ih.fetch_next()
36
37 if ih.head is not None:
38 heapreplace(h, ih)
39 else:
40 heappop(h)
41