Sequence
- Last Updated: November 22, 2019
- 1 minute read
- Corticon
- Documentation
Sequence operators act on collections that have already been ordered by a sorting operator (see sortedBy and
sortedByDesc). In other words, sequence operators operate on collections
that have been turned into sequences. The notation <Sequence> used below, is shorthand for a completed sorting
operation. For example:
<Collection> -> sortedBy(<Attribute>)
produces a <Sequence>, in this
case the elements of <Collection> arranged in
ascending order using <Attribute> as the index.
This <Sequence> can then be used with one of the
sequence operators described below. The design of the Object Constraint Language (upon
which the Corticon Rule Language is based), allows for the “chaining” of operators, so a collection operator and a sequence operator can be
used in the same expression to produce a sequence and identify a particular element of
that sequence in the same step. For example:
<Entity.attribute1> = <Collection> ->sortedBy(<Attribute3>) ->first.<Attribute2>
performs the following:
- Sorts <
Collection> in ascending order according to <Attribute3>, turning it into a <Sequence> - Locates the first element of <
Sequence> - Reads the value of <
Attribute2> of the first element - Assigns the value of <
Attribute2> of the first element to <Entity.attribute1>
Corticon's Sequence operators are as follows:
| Name and Syntax | Returns | Description | |
|---|---|---|---|
| At | |||
<Sequence>
->at(<Integer>) |
Entity | Returns the element at position <Integer>. <Sequence> must be expressed as a unique alias. |
|
| First | |||
<Sequence>
->first |
Entity | Returns the first element of <Sequence>. <Sequence> must be expressed as a unique alias. |
|
| Last | |||
<Sequence>
->last |
Entity | Returns the last element of
<Sequence>. <Sequence> must be expressed as a unique alias. |
|
| SubSequence | |||
<Sequence>
->subSequence(integer1,integer2) |
Entity | Returns a Sequence containing all elements of
<Sequence> between the positions
integer1 and integer2. |
|
| First(number) | |||
<Sequence> ->first(integer) |
Entity | Returns a Sequence containing elements of
<Sequence> from the first element to
integer; in other words, ->first(x) is effectively >subSequence(1,x) |
|
| Last(number) | |||
<Sequence> ->last(integer) |
Entity | Returns a Sequence containing elements of
<Sequence> between the end position of the
collection and integer; in other words, in a sequence of n
elements, ->last(x) is effectively >subSequence(n-x+1,n) |
|
| Trend | |||
<Attribute>
-> <Sequence>.trend |
String | Returns a 4-character string, INCR, DECR, CNST, or
NONE depending on the trend of <Attribute> within <Sequence>. |
|
| mavg(elements) | |||
<Sequence.decimal>
.mavg(elements:Integer) |
Decimal | Returns a single decimal value that is the average of the number of elements specified. | |
| Sorted Alias: next | |||
->next |
Operates against a Sorted Alias (a special cached Sequence) inside a filter expression. The Rulesheet is set into a Ruleflow that iterates to bind the alias in each successive invocation to the next element in the sequence. For more information, see the topic Sorted aliases . | ||