Ascending and Descending (SortOrder functions)
Create SortOrder object to sort in ascending or descending order (SortOrder class)
These shared methods create a new instance of the SortOrder class.
The ordering direction of the new instance is given by the constructor name:
Ascending is low-to-high; Descending is high-to-low.
The sorting key of the new instance is specified by the input parameter to the constructor. This parameter is a function that gets applied to each item in the collection that is being sorted, and it must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, Longstring, or Unicode) value.
Ascending/Descending syntax
%sortOrder = [%(SortOrder For itemType):]Ascending[( [itemFunction])]
%sortOrder = [%(SortOrder For itemType):]Descending[( [itemFunction])]
Syntax terms
%sortOrder | A SortOrder object variable to contain the new object instance. |
---|---|
%(SortOrder For itemtype) | This optional specification of the class in parentheses indicates that the method is shared and does not operate on a specific instance. If you use this option, however, you must include the collection item type to which the selection expression will be applied, like this: %(SortOrder For itemtype): |
itemFunction | A method value (a method name literal, a method variable, a class Variable,
or even a method that returns a method value) for a method
that operates on objects of the type specified on the
declaration of the collection being sorted, and that returns a numeric or
string value.
|
Usage Notes
- For more information about the itemFunction parameter, see "Specifying a SortOrder's sort key method".
- Ascending and Descending are virtual constructors and as such can be called with
no method object, with an explicit class specification, or with an object variable of the class,
even if that object is Null:
%sortOrder = Descending(itemFunction) %sortOrder = %(SortOrder for float):Descending(itemFunction) %sortOrder = %sortOrder:Descending(itemFunction)
- The parameter in the Ascending and Descending methods is a method value, not a User Language expression, and you may not specify a function that itself has an argument. In order to do this, see the example using a Local function, which shows a way to apply such a function in a sort.
- As of Sirius Mods version 7.6, the
default SortOrder itemFunction value is This, a
method value that is valid for User Language intrinsic method objects only.
The identity method This returns the value of the
method object to which it is applied.
The following statements are therefore equivalent:
%sortOrder = Descending(this) %sortOrder = Descending
Note: Using the default SortOrder above on a non-intrinsic method object produces a compilation error.