@mirei/ts-collections
    Preparing search index...

    Function union

    • Creates a set-style union between source and other using an equality comparator.

      Type Parameters

      • TElement

        Type of elements contained by the input sequences.

      Parameters

      • source: Iterable<TElement>

        The initial sequence whose distinct elements lead the union.

      • other: Iterable<TElement>

        Additional sequence whose elements are appended after source when forming the union.

      • Optionalcomparator: EqualityComparator<TElement, TElement>

        Optional equality comparator that determines whether two elements are considered the same. Defaults to the library's standard equality comparator.

      Returns IEnumerable<TElement>

      A deferred sequence containing the distinct elements from source followed by elements from other that are not already present according to comparator.

      Re-throws any error thrown while iterating either sequence or executing comparator.

      Elements yielded by source always appear before contributions from other. Only comparison data required to detect duplicates is buffered, and each input is enumerated at most once.

      const numbers1 = [1, 2, 3, 4, 5];
      const numbers2 = [3, 5, 6, 7];
      const unioned = union(numbers1, numbers2).toArray();
      console.log(unioned); // [1, 2, 3, 4, 5, 6, 7]