init
This commit is contained in:
commit
8c18398ae4
6 changed files with 111 additions and 0 deletions
14
lib/utils.ts
Normal file
14
lib/utils.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export function* zip<A, B>(a: Iterable<A>, b: Iterable<B>): Generator<[A, B], void, void> {
|
||||
const iter_a = a[Symbol.iterator](), iter_b = b[Symbol.iterator]();
|
||||
while (true) {
|
||||
const next_a = next(iter_a), next_b = next(iter_b);
|
||||
if (next_a === null || next_b === null) return;
|
||||
yield [next_a, next_b];
|
||||
}
|
||||
}
|
||||
|
||||
export function next<T>(iterator: Iterator<T>) {
|
||||
const result = iterator.next().value;
|
||||
if (result === undefined) return null;
|
||||
else return result as T;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue