skip to main content
Corticon Studio: Rule Language Guide : Rule operator details and examples : Sorted by
 

Try Corticon Now

Sorted by

SYNTAX

<Collection> ->sortedBy(<Attribute2>) -> sequence operator.<Attribute1>

DESCRIPTION

Sequences the elements of <Collection> in ascending order, using the value of <Attribute2> as the index, and returns the <Attribute1> value of the element in the sequence position determined by the sequence operator. A sequence must be created before any sequence operator ( ->first, ->last, or ->at) is used to identify a particular element. <Attribute1> and <Attribute2> must be attributes of <Collection>.
<Attribute2> may be any data type except Boolean. Strings are sorted according to character precedence – see Character precedence: Unicode and Java Collator<Collection> must be expressed as a unique alias.
See Advanced Collection Syntax and special statement block syntax for more examples of usage.

USAGE RESTRICTIONS

The Operators row of the table in Summary Table of Vocabulary Usage Restriction applies. No special exceptions.

RULESHEET EXAMPLE 1 - USED IN A CONDITION

This sample Rulesheet uses ->sortedBy in a conditional expression to create an ascending sequence from collection with decimal1 as the index.  ->first.string1 is used to return the value of the string1 attribute of the first element of the sequence. If the value of string1 is Joe, then boolean1 attribute of Entity1 is assigned the value of true.

SAMPLE RULETEST 1

A sample Ruletest provides a collection of three elements, each with a decimal1 and string1 value. Input and Output panels are shown below.

RULESHEET EXAMPLE 2 – USED IN AN ACTION

This sample Rulesheet uses ->sortedBy in an action expression to create an ascending sequence from collection with decimal1 as the index. ->first.string1 is used to return the value of the string1 attribute of the first element of the sequence. The value of string1 is assigned the value of Joe if boolean1 attribute of Entity1 is true, if false it is assigned the value of Mary.

SAMPLE RULETEST 2

A sample Ruletest provides a collection of three elements, each with a decimal1 and string1 value. Input and Output panels are shown below.