Skip to content

Erase

Name Mandatory Description Default Type
⬅️ Input Any input is ignored. Any
Output ➡️ The input to this shard is passed through as its output. Any
Indices No One or multiple indices to filter from a sequence. none AnyVar(Any)
Name No The name of the variable. `` StringVar(Any)
Key No The key of the value to erase from the table (nested table). none Any
Global No If the variable is or should be available to all of the wires in the same mesh. false Bool

Deletes an index or indices from a sequence or a key or keys from a table.

Details

Erase deletes single or multiple elements (from sequences) and key-value pairs (from tables).

For a sequence, this shard expects the index (or a sequence of indices in descending order) of the element(s) to be erased, followed by the name of the sequence variable in the :Name parameter.

For a table, this shard expects the key (or a sequence of keys) of the key-value pair(s) to be erased, followed by the name of the table variable in the :Name parameter.

This shard works on both sequences and tables. Parameter :Key applies only to tables.

Since 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), both parameters :Global and :Name are used in combination to identify the correct variable to erase.

Any input to this shard is ignored and instead passed through as its output.

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
; erase single element from sequence
[100 200 300 400] >= seq1
Erase([1] Name: seq1)
Log("output") ; => output: [100 200 300 400]      
seq1 | Log("seq1") ; => seq1: [100, 300, 400]

; erase multiple elements from sequence
[100 200 300 400] >= seq2
Erase([2 0] Name: seq2)
seq2 | Log ; => [200, 400]

; erase single key-value pair from table        
{k1: 10 k2: 20 k3: 30}
ExpectTable ; to make it a dynamic table
>= tab1
Erase("k2" Name: tab1)
tab1 | Log ; => {k3: 30, k1: 10}

; erase multiple key-value pairs from table
{k1: 100 k2: 200 k3: 300}
ExpectTable ; to make it a dynamic table
>= tab2
Erase(["k3" "k1"] Name: tab2)
tab2 | Log ; => {k2: 200}

; erase from same-name local and global sequences
[1 2 3] >= seq ; create local sequence
[1 2 3] | Set(seq Global: true) ; create global sequence
Erase([2 0] Name: seq) ; erase from local sequence
Get(seq) | Log ; => [2]
Erase([1] Name: seq Global: true) ; erase from global sequence
Get(seq Global: true) | Log ; => [1, 3]

; erase from same-name local and global tables
{k1: 1 k2: 2 k3: 3} | ExpectTable >= tab ; create local table   
{k1: 1 k2: 2 k3: 3} | ExpectTable | Set(tab Global: true) ; create global table   
Erase(["k3" "k1"] Name: tab) ; erase from local table
Get(tab) | Log ; => {k2: 2}
Erase(["k2"] Name: tab Global: true) ; erase from global table
Get(tab Global: true) | Log ; => {k3: 3 k1: 1}

[info] Set - Warning: setting an already exposed variable "seq", use Update to avoid this warning.
[info] Set - Warning: setting an already exposed variable "tab", use Update to avoid this warning.
[info] [sample-wire] output: [100 300 400]
[info] [sample-wire] seq1: [100 300 400]
[info] [sample-wire] [200 400]
[info] [sample-wire] {k1: 10 k3: 30}
[info] [sample-wire] {k2: 200}
[info] [sample-wire] [2]
[info] [sample-wire] [1 3]
[info] [sample-wire] {k2: 2}
[info] [sample-wire] {k1: 1 k3: 3}