Push¶
Name | Mandatory | Description | Default | Type |
---|---|---|---|---|
⬅️ Input |
The value to push into the sequence. | Any |
||
Output ➡️ |
The input to this shard is passed through as its output. | Any |
||
Name |
No | The name of the variable. | `` | String Var(Any) |
Key |
No | The key of the value to write in the table (parameter applicable only if the target variable is a table). | none |
Any |
Global |
No | If the variable is available to all of the wires in the same mesh. | false |
Bool |
Clear |
No | Whether to clear this sequence at every wire iteration. This only works if it's the first push. The default is true. | true |
Bool |
Pushes a new value into a sequence variable. If the variable does not exist, it will be created.
Details¶
Push
updates sequences and tables by pushing elements and/or sequences into them.
The name of the variable to update should come from the :Name
parameter and the new update value(s) should come from the shard's input.
For existing sequences Push
pushes in the new elements. If a sequence doesn't exist then Push
will create it while pushing in the first element. These elements may be string constants, numerics, or even sequences themselves.
For tables Push
can update only those existing keys whose values are of the type sequence. In such cases Push
can push in new elements in those key-value pair sequences. The key to be updated must be passed in via the :Key
parameter.
Note
- Do not use
Push
to update any variables created bySet
(or its aliases>=
/>>=
).Push
is best used to update variables that were themselves created byPush
(first push). - Though, if really want to do (1.) you can offload the current sequence into another sequence variable, push new values into it, and update the table with this sequence variable (see the last code example).
The :Global
parameter controls whether the created variables can be referenced across wires (:Global
set to true
) or only within the current wire (:Global
set to false
, default behaviour).
Variables may be locally scoped (created with (:Global false)
; exists only for current wire) or globally scoped (created with (:Global true)
; exists for all wires of that mesh). Hence, in update mode (i.e. when you apply Push
to an existing variable) the :Global
parameter is used in conjunction with the :Name
parameter to identify the correct variable to update.
The parameter :Clear
controls whether we should clear out this sequence after every wire iteration (Clear
set to true
, default behaviour) or should the sequence data persist across wire iterations (Clear
set to false
).
The input to this shard is the new update value that is to be pushed into the sequence/table being modified. This value is also passed through as this shard's output.
Note
Push
has two aliases: >>
which is an alias for (Push ... :Clear true)
, and >>!
which is an alias for (Push ... :Clear false)
. See the code examples at the end to understand how these aliases are used.
Examples¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
[info] Set - Warning: setting an already exposed variable "table2", use Update to avoid this warning.
[info] [sample-wire] .seq1: [1]
[info] [sample-wire] .seq1: [1 2]
[info] [sample-wire] .seq2: [[10 20]]
[info] [sample-wire] .seq2: [[10 20] 30]
[info] [sample-wire] .seq3: []
[info] [sample-wire] .seq3: [1]
[info] [sample-wire] .seq3: [1 2]
[info] [sample-wire] {A: []}
[info] [sample-wire] {A: [1]}
[info] [sample-wire] {A: [1 2]}
[info] [sample-wire] [Local]
[info] [sample-wire] [Global]
[info] [sample-wire] [Local Local2]
[info] [sample-wire] [Global Global2]
[info] [sample-wire] .seq4: [Hello]
[info] [sample-wire] .seq4: [Hello World]
[info] [sample-wire] {k1: [1 2 3]}
[info] [sample-wire] [1 2 3 4]
[info] [sample-wire] {k1: [1 2 3 4]}