Skip to main content

Function: union()

union<ElementType>(...iterables: IterableResolvable<ElementType>[]): IterableIterator<ElementType>

Creates an iterable with the elements that are in either input iterable.

Type Parameters

Type Parameter
ElementType

Parameters

ParameterTypeDescription
...iterablesIterableResolvable<ElementType>[]The iterators to combine.

Returns

IterableIterator<ElementType>

An iterator that yields the union of the provided iterators.

Example

import { union } from '@sapphire/iterator-utilities';

const iterable1 = [1, 2, 3];
const iterable2 = [3, 4, 5];
console.log([...union(iterable1, iterable2)]);
// Output: [1, 2, 3, 4, 5]

Defined in

projects/utilities/packages/iterator-utilities/src/lib/union.ts:20