Sort¶
Name | - | Description | Default | Type |
---|---|---|---|---|
<input> |
Any input is ignored. | |||
<output> |
Output is the sorted 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]] |
|
Desc |
If sorting should be in descending order, defaults ascending. | false |
Bool |
|
Key |
The shards to use to transform the collection's items before they are compared. Can be None. | None |
Shard [Shard] |
Sorts the elements of a sequence. Can also move around the elements of a joined sequence in alignment with the sorted sequence.
Details¶
Sort
sorts all the elements of the sequence that has been passed to it in the :Name
parameter based on the value of the :Desc
parameter. If :Desc
is set to true the sequence is sorted in descending order, else it's sorted in the ascending order (which is the default behaviour).
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.
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 propogated to the corresponding elements of the joined sequence (corresponding rows in the joined table).
In this case the operation is changing of indices (position) of selected elements (selected rows) in one sequence (table) leading to an equivalent change of indices (position) of corresponding elements (connected rows) of the joined sequence (joined table).
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 |
|
[info] [shards/General/Sort/Sort.edn] seq1: [1 3 5 8 9]
[info] [shards/General/Sort/Sort.edn] seq2: [9 8 5 3 1]
[info] [shards/General/Sort/Sort.edn] seq3: [9 8 5 3 1]
[info] [shards/General/Sort/Sort.edn] seq4: [1 3 5 8 9]
[info] [shards/General/Sort/Sort.edn] seqJ: [c d b e a]