Skip to content

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. `` StringVar(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

For existing sequences Push pushes in the new element. If a sequence doesn't exist then Push will create it while pushing in the first element.

If the variable to be updated is a table, a key needs to be specified in the Key parameter. If the key does not exist, Push will create a new key and a new sequence for its value.

The Global parameter controls whether the created by Push 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, is Push is updating an existing variable, the Global parameter is used in conjunction with the Name parameter to identify the correct variable to update.

Note

Push has an two alias: >>

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
; create and update sequence with Push; value available only to current wire
1 | Push(Name: seq1)                    ; create a sequence by pushing the first element
seq1 | Log(".seq1")                     ; sequence created => [1]
2 | Push(Name: seq1)                    ; push one more element into sequence
seq1 | Log(".seq1")                     ; sequence updated => [1, 2]

; create and update sequence with Push; value available to all wires on mesh
[10 20] | Push(Name: seq2 Global: true) ; create sequence with two elements
seq2 | Log(".seq2")                     ; sequence created => [10, 20]
30 | Push(Name: seq2 Global: true)      ; push one more element into sequence
seq2 | Log(".seq2")                     ; sequence updated => [10, 20, 30]

; create empty sequence with Sequence; add elements with Push
Sequence(Name: seq3)                    ; create empty sequence
seq3 | Log(".seq3")                     ; empty sequence created => []
1 | Push(Name: seq3 Clear: false)       ; push an element into sequence
seq3 | Log(".seq3")                     ; sequence updated => [1]               
2 | Push(Name: seq3 Clear: false)       ; push another element into sequence
seq3 | Log(".seq3")                     ; sequence updated => [1, 2]    

; create empty table with Table; add/update key sequence values with Push
Table(table1)                           ; created an empty table
table1 | Log                            ; table created => {}
1 | Push(table1 "A")                    ; push new key "A" with sequence value "[1]"
table1 | Log                            ; table key/value updated => {A: [1]}
2 | Push(table1 "A")                    ; push new element into key "A" existing sequence
table1 | Log                            ; table key/value updated => {A: [1, 2]}   

; create and update local/global sequence variables
"Local" | Push(seq)                     ; create local sequence variable with first push
"Global" | Push(seq Global: true)       ; create same-name global sequence variable with first push
Get(seq) | Log                          ; get local variable => [Local]
Get(seq Global: true) | Log             ; get same-name updated global variable => [Global]
"Local2" | Push(seq)                    ; push new value into local sequence variable
"Global2" | Push(seq Global: true)      ; push new value into same-name global sequence variable
Get(seq) | Log                          ; get updated local sequence variable => [Local, Local2]
Get(seq Global: true) | Log             ; get updated global sequence variable => [Global, Global2]

; Using a Push alias: >> is alias for Push(Clear: true) 
"Hello" >> seq4                         ; create sequence by pushing the first element
seq4 | Log(".seq4")                     ; sequence created => [Hello]
"World" >> seq4                         ; update the sequence by pushing one more element
seq4 | Log(".seq4")                     ; sequence updated with second element => [Hello, World]

; Technique to update a non-push created Tables sequence values with Push
{k1: [1 2 3]} >= table2                 ; table is created using Set
table2 | Log                            ; table with key/value pair created => {k1: [1 2 3]}
Get(table2 Key: "k1") >= seqvar         ; target value offloaded into a sequence variable
4 | Push(seqvar)                        ; update sequence variable using Push
seqvar | Log                            ; sequence variable updated => [1, 2, 3, 4] 
{k1: seqvar} >= table2                  ; update table key sequence value with modified sequence variable                      
table2 | Log                            ; targeted table key updated with required sequence values => {k1: [1 2 3 4]}

[warning] line_info: File path  is invalid
[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] {}
[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]}