collectlist
Name | Type | Description | Optional |
---|---|---|---|
input |
?0 |
element to be added to the list |
no |
include |
?1 (interpreted as boolean) |
if true, add current input to the list |
yes |
complete |
?2 (interpreted as boolean) |
if true, output the accumulated list and reset the accumulator to the empty state |
no |
Name | Type | Description | Optional |
---|---|---|---|
output |
list<?0> |
the accumulated list, output when the complete input is true |
no |
collectlist
reads its three inputs ports. if include
is true (or if the include
port is not connected), the input
is added to the accumulated list. if complete
is true, the accumulated list is output, and the accumulator is reset to empty. Note that there is no output except when the complete
input is true. It is recommended that you read the Iteration section of the Dataflow in Coreograph document in addition to the information presented here.
See the Special Nodes example collectlist:
The list of integers [ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 ]
is passed into foreachlist
, which outputs the elements of the list in order, one by one, from its top output port. From its bottom output port it outputs false for every element except the last, and true
for the last one. We will explore foreachlist
in more detail below.
Each element of the input list passes through the expr
node labeled _0 * 2
. This expression multiplies each input value (represented by _0
) by two. The result is the sequence of integers 2, 4, 6, 8, 10, 10, 8, 6, 4, 2 fed into the top input of the collectlist
node. The collectlist
node accumulates this sequence into the list [ 2, 4, 6, 8, 10, 10, 8, 6, 4, 2 ]
, and outputs the entire accumulated list when it receives true
on its bottom input, namely, for the final element of the input sequence 2, 4, 6, 8, 10, 10, 8, 6, 4, 2.
Finally, the logJSON
node prints the result list emitted by collectlist
. You may see the result by choosing Run
from the Actions
menu:
It adds a few tokens in front of its banner ("the collected list"), and then displays the list that is passed to it in JSON syntax. We will explore logJSON
in more detail below.