🎡 Returns an array of unique values combined from all provided collections.
It uses isEql for deep comparison of values.
Venn Diagram
Syntax
import { union } from '@opentf/std';
union(
collections: unknown[][] = [],
by?: (val: unknown) => unknown
): unknown[]Parameters
collections: An array of arrays to combine.by: An optional iteratee invoked for each element to generate the criterion by which uniqueness is computed.
Returns
A new array containing the unique union of the collections.
Examples
const evens = [2, 4, 6, 8];
const squares = [1, 4, 9];
union([evens, squares]) //=> [2, 4, 6, 8, 1, 9]
const setA = [1, 2, 3];
const setB = [2, 3];
const setC = [2, 3, 4, 5];
union([setA, setB, setC]) //=> [1, 2, 3, 4, 5]