sort()¶
Info
New in Atfinity 17.
Description¶
sort() orders a list by a key the arrow function computes for each element, ascending.
Elements with the same key keep the order they had in the list.
It is not the method version of SORT, which orders elements by their own value or, given a field name, by
one field of each dictionary.
Where that is enough the two agree, so SORT(people, 'age') and people.sort(person => person.age) order a list of
dictionaries the same way.
Reach for sort() where the key has to be computed rather than looked up, such as person => 0 - person.age, or read
off an instance, which SORT cannot order by a field at all.
Syntax¶
Returns: a new list with the same elements in key order, or unknown if the list itself is unknown.
The keys have to be comparable with each other, so sort numbers by a number and text by text.
Example¶
This returns the two entries with Anna first, ordered by age, while the elements themselves stay whole.
For a descending order, sort by the negated key:
This puts Laura first.
Text has no negation, so wrap the result in REVERSE instead.
That is not the same operation: REVERSE also flips the order of elements that share a key, which sorting by a
negated key leaves alone.
Empty lists¶
[].sort(number => number) evaluates to [].