1 | import { AsyncIterableX } from './asynciterablex';
|
2 | import { arrayIndexOfAsync } from '../internal/arrayindexof';
|
3 | import { comparerAsync } from '../internal/comparer';
|
4 | export class UnionAsyncIterable extends AsyncIterableX {
|
5 | constructor(left, right, comparer) {
|
6 | super();
|
7 | this._left = left;
|
8 | this._right = right;
|
9 | this._comparer = comparer;
|
10 | }
|
11 | async *[Symbol.asyncIterator]() {
|
12 | let map = [];
|
13 | for await (let lItem of this._left) {
|
14 | if ((await arrayIndexOfAsync(map, lItem, this._comparer)) === -1) {
|
15 | map.push(lItem);
|
16 | yield lItem;
|
17 | }
|
18 | }
|
19 | for await (let rItem of this._right) {
|
20 | if ((await arrayIndexOfAsync(map, rItem, this._comparer)) === -1) {
|
21 | map.push(rItem);
|
22 | yield rItem;
|
23 | }
|
24 | }
|
25 | }
|
26 | }
|
27 | export function union(left, right, comparer = comparerAsync) {
|
28 | return new UnionAsyncIterable(left, right, comparer);
|
29 | }
|
30 |
|
31 |
|