collectmap
Name | Type | Description | Optional |
---|---|---|---|
key |
?0 |
key to be added to the map |
no |
value |
?1 |
value to associate with current key input |
no |
include |
?2 (interpreted as boolean) |
if true, add current key/value pair to the map |
yes |
Name | Type | Description | Optional |
---|---|---|---|
output |
map<?0>to<?1> |
the accumulated map, output when the complete input is true |
no |
collectmap
reads its four inputs ports. if include
is true (or if the include
port is not connected), the key
and value
association is added to the accumulated map. if complete
is true, the accumulated map 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.
collectlist
, collectset
, and collectvector
have the same shape: three input ports on the left, one output port on the right. The collectmap
special node is slightly different:
collectmap
has input ports for a key and a value, in place of the single element input port of collectlist
, collectset
and collectvector
. The Special Node example collectmap
has a modified structure in which both keys and values are fed to the collectmap
node:
A map has some properties of a set, namely, keys are unique and occur at most once in the map. Put differently, there are no repeated keys in a map just as there are no repeated elements in a set. Running the example gives this result:
The keys are processed in the order "a", "b", "c", "d", "e", "a", "b", "c", "d", "e", and the corresponding values are processed in the order 1, 2, 3, 4, 5, 6, 7, 8, 9, 0. The first time the key "d" is received by the top input to collectmap
, the corresponding value 4 is received on the second input, and "d" is mapped to 4. The second time "d" is received by the top input, the corresponding value 9 is received on the second input, and "d" is re-mapped to 9. The final result is that "d" is mapped to 9.
There a slight complication that did not occur in the earlier collect examples: the number of keys (coming from the upper once
node) must agree with the number of values (coming from the lower once
node). If they do not agree, then some keys or values will be unconsumed. The foreachlist
nodes output the value true
from their lower output port for the last element of the list they are iterating over, and false
otherwise. collectmap
takes this boolean indicator in its lowest input port to indicate when the collected map is complete and should be output. If however the foreachlist
nodes don’t agree about the number of elements, one will output true
when the other outputs false
. In order to detect this condition and feed a consistent boolean value to the collectmap
node, we perform an and
operation on the boolean outputs of the foreachlist
nodes, assert
that this and
value is true, and feed it to the collectmap
operation. If the input lists disagree in length, this assertion will be triggered and will print an error message. You can try it by modifying the project like this:
and selecting the Run
action:
presently, runtime errors refer to line positions in the transpiled project. You can download this file using the Transpile action. Ultimately we will cause runtime errors in transpiled projects to refer to project positions (the nodes and links of a diagram) instead.
|