First NUMBER
- Last Updated: November 6, 2023
- 2 minute read
- Corticon
- Version 6.3
- Documentation
SYNTAX
<Sequence> ->first(integer)
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 sorting 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).
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.
A sample Ruletest provides a collection of five elements, each with a
decimal1 value. Input and Output panels are
shown below.
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:
The sample Ruletest shows the two entities with the highest values are copied to the results sequence: