Operator Scope of Action:
Operator First Added:
Each item in the list is bound in turn to label, and then the expression is evaluated).
label is essentially the same as the loop variable used by the List.each() operator. In the examples below, for clarity the label value "anItem" is used, but as with any loop variable a shorter less expressive values such a "x" can be used (e.g. by more expert users).
The operator applies the action code expression to each list item in turn. The result of expression on label is returned as List-type data. The operator always returns a list of all the results, i.e. the size of the input and output lists are the same. By comparison, this may not be the case with the similar List/Set.collect_if() operator.
If $MyList is "1;2;3;4;5", anItem, is 1, then 2, etc. For example:
$MyListA = $MyList.collect(anItem,anItem+1); returns 2;3;4;5;6
$MyListA = $MyList.collect(anItem, anItem* anItem); returns 1;4;9;16;25
If $MyList is "Winken;Blinken;Nod", then:
$MyListA = $MyList.collect(anItem, anItem.lowercase); returns "winken;blinken;nod"
List/Set.collect() vs. collect()
Although the two appear similar. This operator works directly on the source list values, whereas collect() creates a list of $Path values and returns on an attribute value from each of those paths.