5. Counting, summing, and stable distinct collection
Aggregations traverse in encounter order with a private zero-initialized accumulator. Counting contributes one; summing contributes the current value with checked addition. Empty traversal returns zero, and duplicates contribute independently.
Historical language area
The program accepts an integer sequence named input.
The program computes the following result.
Collect the input values in encounter order into a fresh sequence. Retain each value only when it is absent from the collected sequence, using linear search.This source documents the earlier aggregation grammar. It is not part of the current callable-Go example set; see the verified examples for source paired with generated Go.
The verified result is [4,7,8]. Linear membership reads the destination already accumulated, so only first occurrences survive. If a transformation clause is present, the collected sequence means the transformed values already appended—not a hidden set of original values.
The profile contains a set/hash policy, but its realization is deferred. Use the executable linear sequence policy shown here.
Exercise
What do stable distinct collection, count, and sum return for an empty sequence?
Verified solution
Stable distinct returns [] with type sequence<int64>. Count and sum each return 0 with type int64.