(
...iterables: { [K in keyof T]: Iterable<T[K]> }
)
| 1 | export function* zip<T extends Array<unknown>>( |
| 2 | ...iterables: { [K in keyof T]: Iterable<T[K]> } |
| 3 | ): Iterable<{ [K in keyof T]: T[K] | undefined }> { |
| 4 | const iterators = iterables.map((iterable) => iterable[Symbol.iterator]()); |
| 5 | |
| 6 | while (true) { |
| 7 | const values = []; |
| 8 | let hasMore = false; |
| 9 | for (const iterator of iterators) { |
| 10 | const { done, value } = iterator.next(); |
| 11 | hasMore ||= !done; |
| 12 | values.push(value); |
| 13 | } |
| 14 | if (!hasMore) { |
| 15 | return; |
| 16 | } |
| 17 | yield values as T; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | export async function* zipAsync<T extends Array<unknown>>( |
| 22 | ...iterables: { [K in keyof T]: AsyncIterable<T[K]> } |
no outgoing calls
no test coverage detected