🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators asSequence
Created by Alexandra on 2017-08-13 · Last edited by Colline.ssali on 2025-12-12.


The asSequence() operator in OCL is used to convert a value or collection into a Sequence, which is an ordered collection that may contain duplicates. Unlike Sets, Sequences preserve the order of elements, making them useful when the position of items matters or when you need predictable iteration. If asSequence() is applied to a single object, it produces a Sequence containing only that object.

Returns a Sequence containing all elements of self. Element ordering is preserved when possible.

Expression Result
Sequence{1, 2.0, '3'}->asSequence() Sequence{1, 2.0, '3'}
Bag{1, 2.0, '3'}->asSequence() Sequence{2.0, 1, '3'}
OrderedSet{1, 2.0, '3'}->asSequence() Sequence{1, 2.0, '3'}
Set{1, 2.0, '3'}->asSequence() Sequence{'3', 1, 2.0}

Example:

Department.allInstances.asSequence()