the singularity of being and nothingness
Posts tagged StructFilter()
ColdFusion 10: Filter Functions
Feb 20th
Posted by existdissolve in ColdFusion
In the vein of my last post on ColdFusion 10’s new ArrayEach() and StructEach() functions, there are some other related functions that help with the very common task of filtering arrays, structs, and list. The new functions are ArrayFilter(), ListFilter(), and StructFilter().
Like ArrayEach() and StructEach(), the new filter methods have a “function” parameter (which can also be either an inline function or a named function). However, unlike ArrayEach() and StructEach() which return nothing, the new filter functions return a new array, list, or struct, respectively.
To accomplish this, you need to return a boolean from the function parameter. If the current array element, list item, or structure value matches some criteria and returns “true”, it will be added to the new returned array/list/structure. Conversely, if it fails the criteria and returns “false,” it will be excluded from what is returned.
An ExampleNOTE: The array/list/struct filter() functions return NEW arrays/lists/structures. The original arrays/lists/structs against which the filter() functions are called are unaffected.
Let’s say that we have a simple set of “circles” for a Google+ account which includes a circle for friends, one for co-workers, and another for family. We might model this data like so:
'circles' = { 'friends': ['Lucas','Phil','Dave','Brian','Dillon'], 'coworkers': ['Tyler','Mike','Doug'], 'family': ['Dean','Jared','Jason'] };
Now, let’s imagine More >