This function breaks the specified enumeration of objects into groups and returns the enumeration of those groups as vectors.
Groups are produced according to the grouping keys generated by the specified subquery for every object from the initial enumeration. Each continuous subsequence of objects with equal grouping keys produces a group. The group members are packed into a vector, in the same order as they followed in the original enumeration.
Further, those vectors are returned as elements of the result enumeration (in the same order as they have been produced).
Parameters:
e
Notes:
null
references are also allowed as enumeration elements.null
, an empty enumeration will be returned.elemVar
The variable reference must be produced using '@'
operator
(see example below).
groupingKeyQuery
The subquery should be prepared using FlexQuery()
function.
The element is passed to it via the variable specified in elemVar
parameter (see example below).
The following expression breaks an incoming enumeration of integers into groups according to their parity, so that each group contains only even or odd numbers.
// create a sample enumeration of numbers
e = Enum (1, 7, 6, 18, 2, 33, 171, 55, 2);
// group the enumeration
groupEnum (
e,
@(Number) N,
FlexQuery ({
// generate a grouping key for each number:
// the remainder of the division by 2
N % 2
})
)
Enum (
Vector (1, 7),
Vector (6, 18, 3),
Vector (33, 171, 55),
Vector (2)
)