This version is out of date, covering development from v9.0.0 to v9.3.0. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

List/Set.collect(label, expression)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 List   [operators of similar scope]

 Dictionary, Set & List operations   [other Dictionary, Set & List operations operators]

 9.0.0

 


List/Set.collect(label, expression)

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.



A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : List/Set.collect(label, expression)