views:

99

answers:

1

Is there a standard library function or built-in construct to concatenate two sequences in JavaFX?

Here a Sequences.concatenate() function is mentioned, but it is nowhere to be seen in the official API.

Of course one could iterate over each sequence, inserting the values into a new sequence e.g:

function concatenate(seqA: Object[], seqB: Object[]) : Object[] {
    for(b in seqB) insert b into seqA;
    seqA;
}

..but surely something as basic as concatenation is already defined for us somewhere..

+4  A: 

It is very simple, since there cannot be sequence in sequence (it all gets flattened), you can do it like this:

var a = [1, 2];
var b = [3, 4];
// just insert one into another
insert b into a;
// a == [1, 2, 3, 4];

// or create a new seq
a = [b, a];
// a == [3, 4, 1, 2];

Hope that helps.

Honza
Thanks, just what I was looking for
James
Inserting into a sequence creates a new sequence as well, as sequences are immutable.
Helper Method