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

Specify the initial enumeration of objects to be grouped.

Notes:

  1. null references are also allowed as enumeration elements.
  2. When this parameter itself is null, an empty enumeration will be returned.
elemVar
The reference to the variable to which the current iterated element of the enumeration is assigned to pass it to the subquery generating the grouping key.

The variable reference must be produced using '@' operator (see example below).

groupingKeyQuery
Specify the subquery that will generate the grouping key for each element of the initial enumeration.

The subquery should be prepared using FlexQuery() function. The element is passed to it via the variable specified in elemVar parameter (see example below).

Returns:

The enumeration of Vector objects representing the groups.

Example:

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 
  })
)
The following enumeration will be returned:

Enum (
  Vector (1, 7),
  Vector (6, 18, 3),
  Vector (33, 171, 55),
  Vector (2)
)