iterate(Vector,...)
function with more powerful capabilities.
This function allows you to generate a vector by elements of another vector, array, or enumeration.
The function iterates by the source's elements and for each of them executes
a subquery specified in the subquery
parameter.
The object returned by the subquery is added to the new vector.
The subquery receives the original element in the predefined
_element
variable accessible within it.
Effectively, this function would be the same as the following block:
v = Vector(); i = fromIndex; while (i < toIndex && i < source.size()) { _element = source.elementAt(i); newElement = // the subquery operators generating // a new element from _element variable v.addElement(newElement); i = i + 1; } return v;
Parameters:
source
Provides the source elements
subquery
The subquery to be executed for each source element and to generate the new element for the new vector. The source element is passed to the subquery via the predefined_element
variable.The subquery should be prepared using FlexQuery() function (see example below).
fromIndex
Index of the first iterated element. If not specified, 0 is assumed.
toIndex
Index after the last iterated element. If not specified, the iteration will include all elements until the end.
Returns:
The new generated vector.Note: If the
source
parameter isnull
, the function will return an empty vector.
See Also:
FlexQuery(), iterate()
Example:
The following script converts a sequence number like "1.2.5.9"
(which initially is simply a string) into a vector of its subnumbers
having the Number
type:
(This may allow, for instance, to use a vector representations to compare such sequence numbers according to their subnumbers.)s = getAttrStringValue ("sequenceNumber"); v = breakString(s, "."); generateVector (v, FlexQuery(toNumber(_element)))