structReduce

Iterates over every entry of the struct and calls the closure to work on the key value pair of the struct. This function will reduce the struct to a single value and will return the value.

structReduce(struct, function(result, key, value [,struct]), initialVal) → returns any

structReduce Argument Reference

struct struct
Required

The input struct.

function any
Required

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

result: the result of the reduce operation after the previous iteration
key: key for the current iteration
value: the value for the current iteration
struct: a reference of the original struct

initialVal any

Initial value which will be used for the reduce operation. The type is any.

Links more information about structReduce

Examples sample code invoking the structReduce function

rainbow = { "Red"="Whero",  "Orange"="Karaka", "Yellow"="Kowhai",  "Green"="Kakariki" }; 
  ui = structReduce(  rainbow, function(previousValue, key, value) 
   { 
 return previousValue & "<dt>#key#</dt><dd>#value#</dd>"; 
  }, 
 "<dl>" 
 ) & "</dl>"; 
 writeDump(rainbow); 
 writeOutput(ui); 

CF 11+ Lucee 4.5+

rainbow = { "Red"="Whero",  "Orange"="Karaka", "Yellow"="Kowhai",  "Green"="Kakariki" }; 
  ui = rainbow.reduce( function(previousValue, key, value) 
   { 
 return previousValue & "<dt>#key#</dt><dd>#value#</dd>"; 
  }, 
 "<dl>" 
 ) & "</dl>"; 
 writeDump(rainbow); 
 writeOutput(ui); 

Fork me on GitHub