OCLOperators insertAt
(Automatically adding template at the end of the page.)
(Adding message template to the top of the page)
Line 1: Line 1:
{{message|Write the content here to display this box}}
=== insertAt ( index : Integer, object : T) : Sequence(T) ===
=== insertAt ( index : Integer, object : T) : Sequence(T) ===
Returns a Sequence containing ''self'' with ''object'' inserted at the *index* position.
Returns a Sequence containing ''self'' with ''object'' inserted at the *index* position.

Revision as of 22:24, 16 June 2024

This page was created by Lars.olofsson@mdriven.net on 2022-07-30. Last edited by Stephanie@mdriven.net on 2025-02-10.

Write the content here to display this box

insertAt ( index : Integer, object : T) : Sequence(T)

Returns a Sequence containing self with object inserted at the *index* position.

Expression Result
Sequence{'a', 'b'}->insertAt(0, 'c') invalid
Sequence{'a', 'b'}->insertAt(1, 'c') Sequence{'c', 'a', 'b'}
Sequence{'a', 'b'}->insertAt(3, 'c') Sequence{'a', 'b', 'c'}
Sequence{'a', 'b'}->insertAt(4, 'c') invalid

Insert an object in a specific place in a collection or association. <collection>.insertAt(<position>, <object>)

Used when you don't want a new object at the end using add.

For associations, it only makes sense to use insertAt on ordered associations.

  • Note that the position is 1-based, not 0.

See also: Association