Function reference · Assumptions and sets

union

Returns the set of values that are in any of the given sets.

Notation

union(set1, set2[, ...])

Write it in an expression: nerdamer('union({1,2},{2,3})'), or in the Playground.

nerdamer.union

nerdamer.union(...args: string | number | bigint | ParserEntity[]): ParserEntity

A method on the default import. Arguments can be strings, as in Notation.

import { union }

import { union } from 'nerdamer/structures';
union(...sets: ParserEntity[]): ParserEntity

Import only this function, from nerdamer/structures.

Parameters

set1, set2, ...
Two or more sets, written {...}.

Returns

A set. Each value appears once.

Examples

2 is in both sets, and appears once.

union({1,2},{2,3})
// → {1, 2, 3}
Open in Playground

More than two sets.

union({a},{b},{a,c})
// → {a, b, c}
Open in Playground

Sets can hold vectors.

union({[1,2]},{[1,2],[3,4]})
// → {[1, 2], [3, 4]}
Open in Playground

Collect the distinct values from a loop, starting from the empty set {}.

block(r:{},each([1,2,1],x,r:union(r,{x})),r)
// → {1, 2}
Open in Playground

If the sets have no value yet, the call is kept as it is.

union(A,B)
// → union(A, B)
Open in Playground

Good to know

  • Every argument must be a set: union({1},[1,2]) is an error.

JavaScript examples

nerdamer.union('{1,2}', '{2,3}').text()
// → {1, 2, 3}

← Back to Function reference