Whatever message this page gives is out now! Go check it out!

union

Last update:
May 18, 2026
Returns the union of this set and another set.

Description

All elements that appear in either set. Duplicate values across the two sets appear once in the result.

Returns

A new Set.

Category

ColdFusion Set member methods

Function syntax

set.union(otherSet)

Parameters

ParameterDescription
otherSetAnother Set.

See also

Example

The following example uses this API in cfscript (syntax: set.union(otherSet)).

<cfscript>
    setA = setNew();
    setA.add(1);
    setA.add(2);
    setA.add(3);

    setB = setNew();
    setB.add(2);
    setB.add(3);
    setB.add(4);

    unionSet = setA.union(setB);
    // Elements: 1, 2, 3, 4 (order depends on set variant)
    writeOutput(unionSet.size()); // 4
</cfscript>
      

Real-world example

Effective permissions equal role defaults union explicit grants for a user.

 <cfscript>
    /**
    * Effective permissions = role defaults UNION explicit grants.
    */
    function effectivePermissions(required any rolePerms, required any explicitGrants) {
        return rolePerms.union(explicitGrants);
    }

    rolePerms = setNew();
    rolePerms.add("READ");
    rolePerms.add("LIST");

    explicit = setNew();
    explicit.add("DELETE");
    explicit.add("READ"); // duplicate across union

    eff = effectivePermissions(rolePerms, explicit);
    writeOutput(eff.size()); // 3
</cfscript>
      

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page