union() function
Returns Iterable/AsyncIterable of the union of the two given iterables - the elements of iterable1 followed by the elements of iterable2 that have not appeared yet, with duplicates removed.
Signature:
typescript
declare function union<T>(iterable1: Iterable<T>, iterable2: Iterable<T>): IterableIterator<T>;Example
ts
const iter = union([1, 2], [2, 3, 4]);
iter.next(); // {value: 1, done: false}
iter.next(); // {value: 2, done: false}
iter.next(); // {value: 3, done: false}
iter.next(); // {value: 4, done: false}
iter.next(); // {value: undefined, done: true}
// with pipe
pipe(
[2, 3, 4],
union([1, 2]),
toArray,
); // [1, 2, 3, 4]