Java Reference
In-Depth Information
When the sequence changes, you can assign a trigger function to process the
change. This is discussed in depth in the next chapter.
A shorthand for declaring a sequence of Integer s and Number s uses a range, a
start integer or number with an end. So, [1..9] is the sequence of the integers
from 1 thru 9, inclusive; the exclusive form is [1..<9] —that is, 1 through 8. You
can also use a step function, so if, for example, you want even positive integers,
use [2..100 step 2] . For numbers, you can use decimal fractions, [0.1..1.0
step 0.1] . Without the step, a step of 1 or 1.0 is implicit.
Ranges may also go in decreasing order. To do this, the first number must be
higher than the second. However, without a negative step function, you always
end up with an empty sequence. This is because the default step is always posi-
tive 1.
var negativeNumbers = [0..-10]; // Empty sequence
var negativeNumbers = [0..-10 step -1]; // 0,-1,-2,...-10
var negativeNumbers = [0..<-10 step -1]; // 0,-1,-2,...,-9
To build sequences that include the elements from other sequences, just include
the source sequences within the square brackets.
var negativePlusEven = [ negativeNumbers, evenNumbers ];
Also, you can use another sequence to create a sequence by using the Boolean
operator. Another sequence is used as the source, and a Boolean operator is
applied to each element in the source sequence, and the elements from the source
that evaluate to true are returned in the new sequence. In the following example,
n represents each item in the sequence of positive integers and n mod 2 == 0 is
the evaluation.
var evenIntegers = positiveIntegers[n | n mod 2 == 0];
One can also allocate a sequence from a for loop. Each object “returned” from
the iteration of the for loop is added to the sequence:
// creates sequence of Texts
var lineNumbers:Text[] = for(n in [1..100]) {
Text { content: "{n}" };
};
// creates Integer sequence, using indexof operator
var indexNumbers = for(n in nodes) {
indexof n;
};
Search WWH ::




Custom Search