Skip to content

Erase

Name - Description Default Type
<input> Any input is ignored. Any
<output> The input to this shard is passed through as its output. Any
Indices One or multiple indices to filter from a sequence. None Int[Int]&Int&[Int]String[String]&String&[String]
Name The name of the variable. "" String&Any
Key The key of the value to read/write from/in the table (this variable will become a table). None String
Global If the variable is or should be available to all of the wires in the same mesh. false Bool

Deletes identified element(s) from a sequence or key-value pair(s) 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
;; 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} >= .tab1
(Erase "k2" :Name .tab1)
.tab1 (Log)                             ;; => {:k3 30, :k1 10}

;; erase multiple key-value pairs from table
{:k1 100 :k2 200 :k3 300} >= .tab2
(Erase ["k3" "k1"] .tab2)
.tab2 (Log)                             ;; => {:k2 200}

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

;; erase from same-name local and global tables
{:k1 1 :k2 2 :k3 3} >= .tab             ;; create local table   
{:k1 1 :k2 2 :k3 3} >== .tab            ;; create same-name global table   
(Erase ["k3" "k1"] .tab)                ;; erase from local table
(Get .tab) (Log)                        ;; => {:k2 2}
(Erase ["k2"] .tab :Global true)        ;; erase from same-name 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] [shards/General/Erase/Erase.edn] output: [100 300 400 200]
[info] [shards/General/Erase/Erase.edn] .seq1: [100 300 400]
[info] [shards/General/Erase/Erase.edn] [200 400]
[info] [shards/General/Erase/Erase.edn] {k1: 10 k3: 30}
[info] [shards/General/Erase/Erase.edn] {k2: 200}
[info] [shards/General/Erase/Erase.edn] [2]
[info] [shards/General/Erase/Erase.edn] [1 3]
[info] [shards/General/Erase/Erase.edn] {k2: 2}
[info] [shards/General/Erase/Erase.edn] {k1: 1 k3: 3}