🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators Sequence
This page was created by Lars.olofsson on 2017-05-25. Last edited by Wikiadmin on 2026-07-29.

You can create an ordered collection of values in an OCL or EAL expression with Sequence{...}; use it when the order in which values are processed matters.

Create a Sequence

A Sequence is an ordered collection. Write Sequence, followed by values enclosed in curly braces.

Sequence{value1, value2, value3}

For example, this expression creates a Sequence of three strings in the stated order:

Sequence{'String', 'EmailAddress', 'PhoneNumber'}

Use a Sequence when you need a fixed list of values for an expression or iteration and want the list to retain its order.

Create a range of integers

Use a range inside a Sequence to create consecutive integers. The following expression creates the integers from 0 through 20:

Sequence{0..20}

This is useful when you need numbers for iteration or numbering. For example, iterate over the values in the range with collect:

Sequence{0..20}->collect(i | DoSomethingWithAnInt(i))

In this example, i is each integer in the Sequence, processed in order from 0 to 20.

Create a Sequence of strings

You can place string literals in a Sequence:

Sequence{'String', 'EmailAddress'}

This is useful when you want to process a known set of labels or values in a defined order. For an example that builds a dynamic collection of strings and converts it to comma-separated text, see Documentation:Collection of strings.

Choose the right collection literal

Use the collection type that expresses the behavior your expression needs.

Collection type Use it when Example
Sequence{...} Element order matters. A Sequence is ordered and may contain duplicates. Sequence{'First', 'Second', 'Third'}
Set{...} You need unique values. A Set contains no duplicates. Set{14, 22, 12}
Bag{...} You need a collection that can contain duplicates, without choosing Sequence for ordering. Bag{14, 22, 14}

Do not use a Set when repeated values are significant, because a Set contains no duplicates. Choose Sequence{...} for an ordered list, including a numeric range.

Related Sequence operations

Sequence{...} creates a new collection literal. To convert an existing value or collection to a Sequence, use asSequence(). To return a new Sequence with an item at the end, use append(); it does not change the source collection.

See also