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

setMap

Last update:
Jun 9, 2026
Iterates over a set, applies a function to each member, and returns a new set.

Description

Builds a new set where each element is the result of applying the callback function to each item in the original set. Since the result is a set, any duplicate values produced by the mapping are automatically removed.

Returns

A new Set.

Category

ColdFusion Set helper utilities

Function syntax

utils.setMap(set, callback)

Parameters

ParameterDescription
setSource set.
callbackFunction returning the mapped value per element.

See also

Example

The following example uses this API in cfscript (syntax: utils.setMap(set, callback)).

<cfscript>
    s = setNew();
    s.add(1);
    s.add(2);
    s.add(3);
    s.add(4);
    s.add(5);
    newSet=setMap(s,function(n){return n*10;});
    writeDump(newSet) //10,20,30,40,50 
</cfscript>
      

Real-world example

Normalize role codes (trim + upper case).

<cfscript>
    // Raw, user-typed permission labels (unique in the UI, messy strings)
    s = setNew();
    s.add(" read ");
    s.add("Write");
    s.add("admin");
    s.add("reAD");   // duplicate after normalize → one entry in result

    // Map to canonical codes your authorization layer expects
    newSet = setMap(s, function (n) {
        return reReplace(trim(uCase(n)), "\s+", " ", "all");
    });

    writeDump(newSet);
    // e.g. READ, WRITE, ADMIN — each once, no leading/trailing space, consistent case
</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