Spec-Zone .ru
спецификации, руководства, описания, API

Sequence Types

Sequences hold a sequence of Object values. Said another way, they have sequence cardinality and any Object as the element specifier.

Sequences can be constructed explicitly:

[ 76, 9, 34, 2]
['red', 'green', 'blue']

Or specified as ranges:

[100 .. 200]

Some examples of variables of sequence type:

var nodes : CustomNode[];
var numbers : Number[];
def primes = [2, 3, 5, 7, 11];

Here the expression [2, 3, 5, 7, 11] is of Integer[] type, so primes is type inferenced to Integer[] type.

Note that unlike arrays in Java, JavaFX sequences are NOT Objects. That means that sequences cannot contain sequences, Nested sequences are automatically flattened. The null value in a sequence context is converted to the empty sequence []. For example, the following are all equalivant:

[45, 9, 88, 13]
[[45, 9], [88, 13]]
[45, null, 9, [], 88, [13]]

Automatic flattening is particularly useful in for-loops

for (x in [1..5]) {
   [x, x*x]
}

Which would have the value:

[1, 1, 2, 4, 3, 9, 4, 16, 5, 25]

Sequences are immutable -- there are thus no operations to modify the value of a sequence. But there are, however, operations to modify the value of a variable of sequence type. The insert and delete expressions, assignment, and element assignment all set a new sequence value into a variable.