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.js 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:

  1. Sorts <Collection> in ascending order according to <Attribute3>, turning it into a <Sequence>
  2. Locates the first element of <Sequence>
  3. Reads the value of <Attribute2> of the first element
  4. Assigns the value of <Attribute2> of the first element to <Entity.attribute1>

Corticon.js'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.