/** * Combines N `ReadableStream`s into a single `ReadableStream` by selecting one of N currently * buffered slots per round, emitting it, refilling that slot from its source stream, and * looping until every stream is exhausted (or `pick` signals stop). * * Different from `zip()`: `zip` advances all N streams per round and combines the values; * `select` advances ONE stream per round and emits one item. K-way merge of sorted streams, * priority-queue merge, and drift-tolerant merge are all `select` use cases. * * Throws `TypeError` if `streams` is missing/empty, `options.pick` is missing or not a function, * or `options.windowSize` is not a positive integer. * * @typeParam S — the tuple type of input streams. * @param streams — non-empty array of `ReadableStream`s. * @param options — required. Must include `pick`; may include `insert`, `remove`, `windowSize`. * @returns a `ReadableStream>` that emits one value per round. */ declare function select< const S extends readonly ReadableStream[] = readonly ReadableStream[] >(streams: S, options: select.SelectOptions): ReadableStream>; declare namespace select { /** * Resolves to the value type of a `ReadableStream` — `R` for `ReadableStream`, otherwise `unknown`. * * @typeParam R — a `ReadableStream` whose value type to extract. */ export type StreamValue = R extends ReadableStream ? V : unknown; /** * Union of value types across the input streams tuple. * * @typeParam S — the tuple type of input streams. */ export type SlotItemType[]> = StreamValue; /** * An entry in the buffer the picker / inserter / remover sees. * * @typeParam T — the value type carried by this slot. */ export interface Slot { /** The value pulled from the source stream. */ item: T; /** The position of the source stream in the input `streams` array. */ index: number; } /** * Options accepted by `select()` (Web variant). * * @typeParam S — the tuple type of input streams. */ export interface SelectOptions< S extends readonly ReadableStream[] = readonly ReadableStream[] > { /** * Required. Given the current buffer of slots, returns the index of the slot to emit and * refill. Any non-integer / out-of-range return value stops the merge. */ pick: (items: readonly Slot>[]) => number; /** * Optional. Places a freshly-pulled slot into `items` (mutates in place). * Default: replace at `lastPos` (or `push` when `lastPos` is undefined). */ insert?: ( items: Slot>[], newSlot: Slot>, lastPos?: number ) => void; /** * Optional. Called when the source stream of `items[lastPos]` has just exhausted; the hook * MUST decrease `items.length` by 1. Default: `items.splice(lastPos, 1)`. */ remove?: (items: Slot>[], lastPos: number) => void; /** * Optional. Per-stream buffer depth. Default `1`. Must be a positive integer. */ windowSize?: number; } } type StreamValue = select.StreamValue; type SlotItemType[]> = select.SlotItemType; type Slot = select.Slot; type SelectOptions< S extends readonly ReadableStream[] = readonly ReadableStream[] > = select.SelectOptions; export default select; export {select}; export type {StreamValue, SlotItemType, Slot, SelectOptions};