StructFilter()

Used to loop over the structure to create a new structure based on the inner function applied to each element that will return true/false if it is to be included

Usage

STRUCTURE = StructFilter( struct, function )
Argument Summary
struct Structure Object
function function to loop over the data, passing in the element as the parameter to each. each function call should return true or false; function(key,element){}

Calling

Supports named-parameter calling allowing you to use the function like:

StructFilter(
   struct=?, 
   function=?
);

Supports passing parameters as a structure using ArgumentCollection:

StructFilter( ArgumentCollection={
   struct : ?, 
   function : ?
} );

Extra

Creates a new structure using only the elements from the first structure, by using the callback function.

<cfscript>
str = {
  name : "alan",
  age : 21,
  dob : now()
};


// Callback function declared that accepts the element
function mapCallbackFilter(k,v){
  return isNumeric(k);
}


// Loop around each element
newstr = StructFilter( str, mapCallbackFilter );
</cfscript>

For each element in the array, the function 'mapCallbackFilter' is called, passing in the current element and the key. The callback function sits within the variable scope of the calling function, so it can interact with variables outside of itself.