Converts the specified array / vector / enumeration into another enumeration, in which some of the source elements may be passed unchanged, some removed and some replaced with new elements produced from the corresponding old ones.
The ordering of elements in the result enumeration will correspond to the original one.
Parameters:
a / v / e
elementVar
acceptQuery
and newElementQuery
subqueries (below).
The variable reference must be produced using '@'
operator
(see example below).
acceptQuery
The subquery should be prepared using BooleanQuery()
function
(see example below).
It will be executed for each source element.
The tested element is received in subquery via the variable, whose reference
must be specified in the elementVar
parameter.
The subquery must return true
to indicated that the element is accepted
or false
to remove it.
When this parameter is null
, all source elements will be accepted.
newElementQuery
The subquery should be prepared using FlexQuery()
function
(see example below).
It will be executed for each accepted source element.
The element is received in subquery via the variable, whose reference
must be specified in the elementVar
parameter.
Any result returned by the subquery will be treated as the element added to the result enumeration in place of the original element.
In particular, you may return the original element itself or any other value
produced from it. Returning the null
is also possible,
which will equally get into the result enumeration.
When this parameter is not specified or null
,
all accepted elements will get into result enumeration as is.
In case when no elements are accepted or the source enumeration is null
,
the result will be the empty enumeration.
FlexQuery(), BooleanQuery()
The following expression converts an enumeration of some numbers into another enumeration, in which only positive initial numbers are accepted and then rounded to integer.
numbers = Enum (-1, 4.1, 0, 1.31, 2.9, -7.4 );
convertEnum (
numbers,
@(Number) number,
BooleanQuery (number > 0),
FlexQuery (round (number))
);
{ 4, 1, 3 }