1 from .peekable import Peekable
4 def sequence(*iterables, by=None, compare=None):
5 if compare is not None:
8 compare = lambda i1, i2: by(i1) <= by(i2)
10 compare = lambda i1, i2: i1 <= i2
12 iterables = [Peekable(it) for it in iterables]
19 for i, it in enumerate(iterables):
21 if next_i is None or compare(it.peek(), iterables[next_i].peek()):
27 yield next(iterables[next_i])