Skip to content

Remove

Name Mandatory Description Default Type
⬅️ Input Any input is ignored. None
Output ➡️ Output is the filtered sequence. [Any]
From No The name of the sequence variable to edit in place. none Var([Any])
Join No Other columns to join sort/filter using the input (they must be of the same length). none NoneVar([Any])[Var([Any])]
Predicate No The shards to use as predicate, if true the item will be popped from the sequence. none Shard[Shard]
Unordered No Turn on to remove items very quickly but will not preserve the sequence items order. false Bool

Removes all elements from a sequence that match the given condition. Can also take these matched indices and remove corresponding elements from a joined sequence.

Details

This shard can also remove elements with the corresponding indices from a joined sequence (passed via the Join: parameter). Remember, Remove doesn't apply the Predicate conditions to the joined sequence, but only removes corresponding elements. For this to work both the sequences must have the same length.

Note

Think of this as the Shards equivalent of a relational database inner join. The main sequence and the joined sequence can be thought of as columns from two different tables inner joined over indices equality. So that the changes in elements of one sequence (rows in the first table) can be propagated to the corresponding elements of the joined sequence (corresponding rows in the joined table).

In this case the operation is deletion of selected elements (selected rows) from one sequence (table) leading to deletion of corresponding elements (connected rows) of the joined sequence (joined table).

The Predicate parameter can take any conditional/logical expression or combination of shards that will result in assertion that can be tested on the sequence elements.

The Unordered parameter can be set to true if you need to make the removal process faster, but then the order of the remaining elements in the resulting sequence elements may not be preserved. By default, this order is preserved.

Remove works only on sequences.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
; remove predicate-satisfying elements from From sequence
[10 20 30] >= seq1
Remove(
    From: seq1
    Predicate: {IsMore(20)}
    Unordered: false
) | Log("output")      ; => output: [10, 20]
seq1 | Log(".seq1") | Assert.Is([10 20])    ; index-2 element matched, removed => .seq1: [10, 20]

; remove corresponding index elements from Join sequence
[10 20 30] >= seq2
[100 200 300] >= seqJ
Remove(seq2 Predicate: {Is(20)} Join: seqJ)
seq2 | Log(".seq2") | Assert.Is([10 30])    ; index-1 element matched, removed from seq2 => .seq2: [10, 30]
seqJ | Log(".seqJ") | Assert.Is([100 300])    ; matched index-1 element removed from seqJ  => .seqJ: [100, 300]

; remove with Unordered true (faster but sequence items order may not be preserved)
[[20 30] [30 40] [40 50]] >= seq3
Remove(seq3 Predicate: {Take(0) | IsLess(30)} Unordered: true)
seq3 | Log(".seq3") | Assert.Is([[40 50] [30 40]])    ; index-0 element matched, removed => .seq3: [[40, 50], [30, 40]]

[info] [sample-wire] output: [10 20]
[info] [sample-wire] .seq1: [10 20]
[info] [sample-wire] .seq2: [10 30]
[info] [sample-wire] .seqJ: [100 300]
[info] [sample-wire] .seq3: [[40 50] [30 40]]