Array union

Arrays and ranges Pure Generic
Array union
A
Result
B

Description

Pure function returning the set union of two arrays: every element of A, then every element of B that A does not already hold, with duplicates dropped from both sides. Order is first-seen, so [sv, en] and [sv, fi] union to [sv, en, fi]. Elements are compared the way Equals compares them. Builds a new array and leaves both inputs untouched; a null array counts as empty.

When to use

Use Array union to merge two lists into one without repeating anything — combining the languages a customer has selected with the ones a campaign already targets, or folding a page of results into an accumulator without re-adding the items it already holds. Because duplicates are dropped within each side as well as between them, it doubles as the way to make a list distinct: union an array with an empty one and every repeat collapses to its first occurrence.

Elements are compared exactly the way Equals compares them, which is worth knowing for decimals and datetimes: 2.0 and 2.00 are different values here, as are the same instant written at two UTC offsets. Model values compare field by field, so two separately built models with identical fields count as one element.

Pins

Input pins

Pin Type Default Notes
A generic[] — The first array. Its elements come first in the result, in their original order. The element type resolves at design-time from the connected source. A null array counts as empty, exactly like leaving the pin unconnected.
B generic[] — The second array. Its elements follow A's, minus any value A already holds. Must hold the same element type as A.

Output pins

Pin Type Notes
Result generic[] A new array holding each distinct value from A and B, in first-seen order. Never null — two null inputs union to an empty array. Both input arrays are left untouched.

Example

Build the set of languages to send a newsletter in. Wire the customer’s preferred languages into the A input and the campaign’s mandatory languages into the B input. The Result output holds each language once, customer preferences first — feed it straight into the Array input of For each to send one mail per language.

To make a single array distinct instead, wire it into A and leave B unconnected: an unwired array pin is an empty array, so the result is A with its repeats removed.

See also