CollectionMap

Calls the given closure with every element in the given collection. the function returns a array or struct (depending on the input) that contains all values returned by the closure.

Returns: object

Usage

CollectionMap( collection, closure [, parallel [, maxThreads ] ] )

Arguments

Argument Description Default
collection
(object, required)

collection to iterate

closure
(function, required)

UDF/Closure that is called with every value in the collection

parallel
(boolean, optional)

execute closures parallel

maxThreads
(number, optional)

maximum number of threads executed, ignored when argument "parallel" is set to false

20

Examples

// 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