You use prepend in an OCL expression when you need an element to appear before every element already in an ordered collection.
Syntax
prepend ( object : T ) : OrderedSet(T)
The operator returns an OrderedSet(T) that contains object first, followed by all elements of self in their existing order.
Parameters and result
| Part | Meaning |
|---|---|
self
|
The ordered collection on which you call prepend.
|
object : T
|
The element to place first. T represents the element type used by the collection.
|
OrderedSet(T)
|
The ordered set returned by the operator. |
Example
If self contains the elements Second and Third, prepending First returns an ordered set with this order:
| Input | Result |
|---|---|
self = [Second, Third]object = First
|
[First, Second, Third]
|
Use prepend when the position of the new element matters and it must be first. The elements already in self follow it in the same order.
Related operators
prepend operates on an ordered collection. It is different from concat, which returns a String by placing one string after another.
For the available operators in the OCL editor, see Documentation:OCL General Operators. For operators that evaluate logical relationships, see Documentation:OCL Boolean Operators.
