MCPcopy Create free account
hub / github.com/banga/git-split-diffs / zip

Function zip

src/zip.ts:1–19  ·  view source on GitHub ↗
(
    ...iterables: { [K in keyof T]: Iterable<T[K]> }
)

Source from the content-addressed store, hash-verified

1export 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
21export async function* zipAsync<T extends Array<unknown>>(
22 ...iterables: { [K in keyof T]: AsyncIterable<T[K]> }

Callers 3

iterFormatHunkSplitFunction · 0.90
getChangesInLinesFunction · 0.90
zip.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected