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])) → returns Struct

Argument Reference for the structMap function

struct

Required: Yes
The input struct.

function

Required: Yes
Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are

key: key for the current iteration
value: the value for the current iteration
struct: a reference of the original struct

Links more information about structMap

Examples sample code invoking the structMap function


Script Syntax

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

Using Member Function

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[v.keyList().first()]; 
 }); 
 writeDump([ original, fixed]); 

Fork me on GitHub