CollectionMap()
Calls the given closure with every element in the given collection. the function returns an array or struct (depending on the input) that contains all values returned by the closure.
CollectionMap( collection=object, closure=function, parallel=boolean, maxThreads=number );
Returns: object
| Argument | Description | Default |
|---|---|---|
|
collection
object,
required
|
edit
collection to iterate Alias: object |
|
|
closure
function,
required
|
edit
UDF/Closure that is called with every value in the collection Alias: function, callback, udf |
|
|
parallel
boolean,
optional
|
edit
execute closures parallel |
|
|
maxThreads
number,
optional
|
edit
maximum number of threads executed, ignored when argument "parallel" is set to false Alias: maxThreadCount |
20 |
Examples
edit// array
people = [ { name = "Alice", age = 32 }, { name = "Bob", age = 29 }, { name = "Eve", age = 41 }];
dump(CollectionMap(people, function(p) { return p.name; }));
// member function
dump(people.map(function(p) { return p.name; }));
// struct
person = { name = "Alice", age = 32, email = "alice@example.com" };
dump(CollectionMap(person, function(key,value) { return isnumeric(value); }));
// member function
dump(person.map(function(key,value) { return isnumeric(value); }));
See also
- Collections
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)