Skip to main content
Skip table of contents

Sequences

Sequence Syntax

Sequences are variable-length collections of elements:

SLICE
module M
{
    sequence<Fruit> FruitPlatter;
}

A sequence can be empty — that is, it can contain no elements, or it can hold any number of elements up to the memory limits of your platform.

Sequences can contain elements that are themselves sequences. This arrangement allows you to create lists of lists:

SLICE
module M
{
    sequence<FruitPlatter> FruitBanquet;
}

Sequences are used to model a variety of collections, such as vectors, lists, queues, sets, bags, or trees. (It is up to the application to decide whether or not order is important; by discarding order, a sequence serves as a set or bag.)

Language Mapping

Default Mapping

A Slice sequence maps to a JavaScript array.

  • For JavaScript, the compiler does not generate a separate class or type.

  • For TypeScript, it generates a type alias.

This allows you to take full advantage of the built-in functionality of JavaScript arrays.

For example:

NONE
sequence<Fruit> FruitPlatter;

Generates the following TypeScript declaration:

TYPESCRIPT
export type FruitPlatter = Fruit[];

Usage

JS
// JavaScript
const platter = [Fruit.Apple];
platter.push(Fruit.Pear);
TYPESCRIPT
// TypeScript
const platter:FruitPlatter  = [Fruit.Apple];
platter.push(Fruit.Pear);

Mapping for Byte Sequences

As an optimization, sequence<byte> maps to the JavaScript Uint8Array type. This representation is more efficient than regular arrays when working with binary data.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.