skip to main content
Corticon Studio: Rule Modeling Guide : Collections : Singletons
 

Try Corticon Now

Singletons

Singletons are collection operations that iterate over a set to extract one arithmetic value - the first, the last, the trend, the average, or the element at a specified position. We saw this behavior when the sortedAlias found the first and last element in an iterative list (as well as the elements in between) in the given order.
To examine this feature, we bring the Aircraft entity and its maxCargoWeight into the scope as well as Cargo (with the alias load) and its attribute weight. The nonconditional action we enter is, literally:
"Show me the maximum cargo weight by examining all the cargo in the load, sorting them by weight from small to large, and returning the smallest one first."
That is entered as:
Aircraft.maxCargoWeight=load->sortedBy(weight)->first.weight
When we extend the test we used for sorted aliases, we need to add an Aircraft with maxCargoWeight to show the result of the test. The result is as expected - the lightest item passed the test.
The same result is output when we modify the rule to select last item when we sort the items by descending weight.
Now we reverse the test to select the first item when we sort the items by descending weight...
...and the heaviest item is output.
Note: Singletons do not operate against an iterative Ruleflow as was required by Sorted Aliases. The tests apply directly to the Rulesheet.