AT-POS
ErrorsCollection

AT-POS

Synthesised documentation from type/Positional type/Range type/Sequence language/subscripts

From type/Positional

See Original text in context

method AT-POS(\position)

Should return the value / container at the given position.

From type/Range

See Original text in context

multi method AT-POS(Range:D: int \pos)
multi method AT-POS(Range:D: int:D \pos)

Checks if the Int position exists and in that case returns the element in that position.

say (1..4).AT-POS(2# OUTPUT: «3␤»

From type/Sequence

See Original text in context

multi method AT-POS(::?CLASS:D: Int:D $idx)
multi method AT-POS(::?CLASS:D: int $idx)

Returns the element at position $idx in the cached sequence.

From language/subscripts

See Original text in context

multi method AT-POS (::?CLASS:D: $index)

Expected to return the element at position $index. This is what postcircumfix [ ] normally calls.

If you want an element to be mutable (like they are for the built-in Array type), you'll have to make sure to return it in the form of an item container that evaluates to the element's value when read, and updates it when assigned to. Remember to use return-rw or the is rw routine trait to make that work; see the example.