structMap

Iterates over every entry of the Struct and calls the closure function to work on the key value pair of the struct. The returned value will be set for the same key in a new struct and the new struct will be returned.

structMap(struct, function(key, value [,struct]){} [, parallel] [, maxThreads]) → returns struct

Member Function Syntax

someStruct.map(function(key, value [,struct]){} [, parallel] [, maxThreads])

Argument Reference

struct struct
Required

The input struct.

callback any
Required

Closure or a function reference that will be called for each of the iteration.

Callback parameters:

  • key*string : The key for the current iteration
  • value*any : The value for the current iteration
  • struct*struct : A reference of the original struct

parallel boolean
Default: false

Lucee 4.5+ true if the items can be executed in parallel
Values:
  • true
  • false

maxThreads numeric
Default: 20

Lucee 4.5+ the maximum number of threads to use when parallel = true

Links more information about structMap

Examples
Sample code invoking the structMap function

original = {
    "one": {
        1: "tahi"
    },
    "two": {
        2: "rua"
    },
    "three": {
        3: "toru"
    },
    "four": { 
        4: "wha"
    }
};
function mapOriginal(k,v) {
    return v[ListFirst(v.keyList())];
}
fixed = structMap(original,mapOriginal);
writeDump([original, fixed]);

CF 11+ Lucee 4.5+

original = {
    "one": {
        1: "tahi"
    },
    "two": {
        2: "rua"
    },
    "three": {
        3: "toru"
    },
    "four": {
        4: "wha"
    }
};
fixed = original.map(function(k,v) {
    return v[ListFirst(v.keyList())];
});
writeDump([original, fixed]);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub