@omniblack/collections 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/fifo.ts +6 -3
package/package.json
CHANGED
package/src/fifo.ts
CHANGED
|
@@ -2,6 +2,9 @@ interface Node<T> {
|
|
|
2
2
|
next?: Node<T>;
|
|
3
3
|
item: T;
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
type Value<T> = T extends Fifo<infer V> ? V : never;
|
|
7
|
+
|
|
5
8
|
export class Fifo<T> {
|
|
6
9
|
max: number | undefined;
|
|
7
10
|
length: number;
|
|
@@ -56,11 +59,11 @@ export class Fifo<T> {
|
|
|
56
59
|
return this.length === 0;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
*zip(...others:
|
|
60
|
-
const all = [this, ...others];
|
|
62
|
+
*zip<U extends Fifo<any>[]>(...others: U): Generator<[T | undefined, ...{ [K in keyof U]: Value<U[K]> | undefined }]> {
|
|
63
|
+
const all: [Fifo<T>, ...U] = [this, ...others];
|
|
61
64
|
|
|
62
65
|
while (all.every((fifo) => !fifo.empty)) {
|
|
63
|
-
yield all.map((fifo) => fifo.pop());
|
|
66
|
+
yield all.map((fifo) => fifo.pop()) as [T | undefined, ...{ [K in keyof U]: Value<U[K]> }];
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
}
|