skip to main content
Corticon Studio: Rule Language Guide : Rule operator details and examples : First (number)
 

Try Corticon Now

First (number)

SYNTAX

<Sequence> ->first(integer)

DESCRIPTION

Returns a ->subSequence of the first integer entities in the collection <Sequence>. Another operator, such as ->sortedBy or ->sortedByDesc, must be used to transform a <Collection> into a <Sequence> before ->first can be used. <Sequence> must be expressed as a unique alias. If integer is larger than the number of entities in the collection, all the entities in the collection are returned. See Advanced Collection Syntax for more examples of usage.

USAGE RESTRICTIONS

The Operators row of the table in Vocabulary usage restrictions does not apply. Special exceptions: last(x) may only be used in Action Rows (section 5 in Sections of Rulesheet that correlate with usage restrictions).

RULESHEET EXAMPLE

This sample Rulesheet uses ->first(2) to select the first two elements of the sequence created by applying ->sortedBy to collection2. Once identified, the first 2 entities will be returned as the sequence collection3.

SAMPLE RULETEST

A sample Ruletest provides a collection of five elements, each with a decimal1 value. Input and Output panels are shown below.
Note: The selected entities and their values are highlighted to improve readability.

RULESHEET EXAMPLE: USING DESCENDING SORT

Sometimes it is easier to understand this type of action when you sort the data in descending order; when thinking of the "the top three sales figures", the first three largest values are what is intended. In this example, the action uses ->sortByDesc to order the collection largest-to-smallest and then moves the top 2 entities to the result sequence:

SAMPLE RULETEST: USING DESCENDING SORT

The sample Ruletest shows the two entities with the highest values are copied to the results sequence:
Note: The selected entities and their values are highlighted to improve readability.