pytoolz/toolz — pull request #58 by eriknw (2013-10-31 21:44:38+00:00)
Title: Corrected and improved `merge_sorted` function.

The same approach as before is used, but the following improvements were made:
(1) Don't use Queue module! Queue is meant for threaded applications, and the
performance sucks because queue methods need to lock and unlock mutexes.
(2) Use heapq module instead of Queue module.
(3) If no key is specified, then use `heapq.merge` for improved efficiency.
(4) Corrected priority of item comparison so values from earlier iterables will
come before later iterables. The order of comparison was changed from
[key(item), item, itnum] to [key(item), itnum], where `itnum` is the index
of the iterable. Note that we don't need to--and shouldn't!--use `item`.
To clarify, the problem with the original implementation is `item` comes
before `itnum`.
(5) Added more tests for my sanity!