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
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 PlaygroundIf the sets have no value yet, the call is kept as it is.
union(A,B)
// → union(A, B)Open in PlaygroundGood 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}