1 | import { IterableX } from './iterablex';
|
2 | import { returnIterator } from '../util/returniterator';
|
3 | export class ZipIterable extends IterableX {
|
4 | constructor(sources) {
|
5 | super();
|
6 | this._sources = sources;
|
7 | }
|
8 |
|
9 | *[Symbol.iterator]() {
|
10 | const sourcesLength = this._sources.length;
|
11 | const its = this._sources.map((x) => x[Symbol.iterator]());
|
12 | while (sourcesLength > 0) {
|
13 | const values = new Array(sourcesLength);
|
14 | for (let index = -1; ++index < sourcesLength;) {
|
15 | const result = its[index].next();
|
16 | if (result.done) {
|
17 | its.forEach(returnIterator);
|
18 | return undefined;
|
19 | }
|
20 | values[index] = result.value;
|
21 | }
|
22 | yield values;
|
23 | }
|
24 | }
|
25 | }
|
26 | export function zip(...sources) {
|
27 | return new ZipIterable(sources);
|
28 | }
|
29 |
|
30 |
|