OCLOperators insertAt
(Created page with "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 OCLO...")
 
(Automatically adding template at the end of the page.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Insert an object in a specific place in a collection or association.
=== insertAt ( index : Integer, object : T) : Sequence(T) ===
<collection>.insertAt(<position>, <object>)
Returns a Sequence containing ''self'' with ''object'' inserted at the *index* position.
{| class="wikitable"
!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>, <nowiki><object>)</nowiki> 
 
Used when you don't want a new object at the end using [[OCLOperators add|add]].  
Used when you don't want a new object at the end using [[OCLOperators add|add]].  


For associations, it's only makes sense to use insertAt on ordered associations.
For associations, it only makes sense to use insertAt on ordered associations.
* Note that the position in 1-based, not 0.
* Note that the position is 1-based, not 0.
See also: [[Association]]
[[Category:OCLOperators]]
{{Edited|July|12|2024}}

Latest revision as of 15:42, 10 February 2024

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

This page was edited 98 days ago on 02/10/2024. What links here