Skip to content

Remove

Name - Description Default Type
<input> Any input is ignored.
<output> Output is the filtered sequence. [Any]
From The name of the sequence variable to edit in place. None &[Any]
Join Other columns to join sort/filter using the input (they must be of the same length). None &[Any][&[Any]]
Predicate The shards to use as predicate, if true the item will be popped from the sequence. None Shard[Shard]
Unordered 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

Remove removes all the elements of the :Name parameter sequence that matches the condition laid out in the :Predicate parameter.

It can also take these condition-matched indices (from the :From sequence) and remove the corresponding elements from a joined sequence (passed via the :Join parameter). Remember, Remove doesn't apply the :Predicate conditions to the joined sequence, but removes corresponding elements from it based on :Predicate matched indices of the main sequence. 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.

Any input to this shard is ignored and its output is the main filtered sequence.

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") ;; 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") ;; index-1 element matched, removed from seq2 => .seq2: [10, 30]
.seqJ (Log ".seqJ") ;; 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") ;; index-0 element matched, removed => .seq3: [[40, 50], [30, 40]]
[info] [shards/General/Remove/Remove.edn] output: [10 20]
[info] [shards/General/Remove/Remove.edn] .seq1: [10 20]
[info] [shards/General/Remove/Remove.edn] .seq2: [10 30]
[info] [shards/General/Remove/Remove.edn] .seqJ: [100 300]
[info] [shards/General/Remove/Remove.edn] .seq3: [[40 50] [30 40]]