mergeSorted<
A>(order,sources):Generator<A,void,unknown>
Defined in: packages/sorted-merge/src/merge-sorted.ts:40
Lazily merge a finite collection of independently iterable sorted sources under the same total order. Keeps duplicates. Equal items retain their order within each source, with earlier sources winning ties. Supply a stable order and keep compared values unchanged while the merge is active.
The first advance calls next() once on each source. Each subsequent advance pulls only from the source of the last emitted value. With k sources, setup takes O(k) time and space, and each output after setup takes O(log(k + 1)) time, excluding input reads and comparator cost. Individual sources may be infinite.
On early return or failure, calls return() once on each opened, unfinished iterator that exposes it. Errors from the order and input iterators propagate. A cleanup error surfaces if the merge was otherwise returning normally. When several iterators fail during cleanup, the first error surfaces after all are tried.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Order<A>
sources
Section titled “sources”Iterable<Iterable<A, any, any>>
Returns
Section titled “Returns”Generator<A, void, unknown>