All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.sorted.html Maven / Gradle / Ivy




    
    Slice expressions
    
    

    
    

    
    

    
    
    
    

    


Sorted expressions

Sorted expressions are used to produce a sorted list from an existing collection.
A Sorted expression is a code fragment which produces a list, whose item type is the same as the item type of the collection being sorted, which can then be used as an input for other operations: print, write, method call and so forth.
A Sorted expression has the form sorted collection where collection is a collection value.

The type of the resulting value is the same as the List value.

Using native sorting

Sorting a collection of simple values is done using native sorting, as follows:

Sorting

Sorting backwards is done by inserting the descending keyword after the sorted one.
In O and M dialects, the desc abbreviated keyword is preferred.

Sorting a collection of custom objects

When sorting custom objects there is no natural order. It is therefore necessary to specify how to compare custom objects.
This is done by using a key on which exists a natural order.

Sorting lists of custom objects by existing key attribute

When a custom object comprises a key, this attribute is used to sort a collection implicitly.

Sorting lists of custom objects by any attribute

Any native attribute can be used to sort a collection explicitly.

Sorting lists of custom objects by expression

Alternately, lists of custom objects can be sorted using expressions as key, as follows:





© 2015 - 2025 Weber Informatics LLC | Privacy Policy