Skip to content

Sort

Name Mandatory Description Default Type
⬅️ Input Any input is ignored. None
Output ➡️ Output is the sorted 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])]
Desc No If sorting should be in descending order, defaults ascending. false Bool
Key No The shards to use to transform the collection's items before they are compared. Can be None. none Shard[Shard]None

Sorts the elements of a sequence. Can also move around the elements of a joined sequence in alignment with the sorted sequence.

Details

This shard can also take final element order of the sorted sequence and apply that to a joined sequence (passed via the Join parameter). For example, if the element at index-7 moved to index-3 in the main sequence due to sorting then in the joined sequence too the element at index-7 would move to index-3. The movement of all elements in the main sequence (post-sort) would be mirrored in the joined sequence. For this to work both the sequences must have the same length.

The Key parameter can take a shard or group of shards to transform the sequence elements before they're compared for sorting. This transformation doesn't actually change the value of the elements in the final sorted sequence (it's used only for sort comparisons).

Sort works only on sequences.

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

See also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
; sort ascending (since default Desc is false)
[9 5 1 3 8] >= seq1
Sort(From: seq1)
seq1 | Log("seq1")  ; sorted ascending => seq1: [1, 3, 5, 8, 9]

; sorting descending (Desc set to true)
[9 5 1 3 8] >= seq2
Sort(seq2 Desc: true)
seq2 | Log("seq2")  ; sorted ascending => seq2: [9, 8, 5, 3, 1]

; sort ascending using a Key
[9 5 1 3 8] >= seq3
Sort(seq3 Key: {Math.Multiply(-1)})
seq3 | Log("seq3")  ; Key transform makes it look like descending sort => seq3: [9, 8, 5, 3, 1]

; sort ascending with a joined sequence
[9 5 1 3 8] >= seq4
["a" "b" "c" "d" "e"] >= seqJ
Sort(seq4 Join: seqJ)
seq4 | Log("seq4")  ; main sequence sorted in ascending order => seq4: [1, 3, 5, 8, 9]
seqJ | Log("seqJ")  ; sorted order applied to joined sequence => seqJ: [c, d, b, e, a]

[info] [sample-wire] seq1: [1 3 5 8 9]
[info] [sample-wire] seq2: [9 8 5 3 1]
[info] [sample-wire] seq3: [9 8 5 3 1]
[info] [sample-wire] seq4: [1 3 5 8 9]
[info] [sample-wire] seqJ: [c d b e a]