Iteration
Syntax
$set.foreach($func)
Description
Applies the func
function to each element of the set
and returns the set of evaluation results. Alternative syntax for map(), if not the result of the mapping but the side effect of the function is relevant.
Parameters
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
set | Set | A set on whose elements func should be called. |
yes | |
func | Function | A function to be executed on the elements of set . |
yes |
Examples
{
a = new(`my.module:MyClass`);
b = new(`my.module:MyClass`);
list = list($a, $b);
$list.foreach(x -> $x.set(`my.module:MyClass#date`, now()));
}
Output: /
Creates two objects of type my.module:MyClass
and assigns them the current date in the date
attribute.