Rules / Types, classes & roles / composite

Positional Reference

Object that supports looking up values by index

What it is #

Position in the hierarchy #

Inherits from
Does
Consumed byIO::Path::Parts, Range, List

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method of #

method of()

Returns the type constraint for elements of the positional container, that is, the T in the definition above, which, as it can be seen, defaults to Mu. It is returned as a type object.

method elems #

method elems()

Should return the number of available elements in the instantiated object.

method AT-POS #

method AT-POS(\position)

Should return the value / container at the given position.

method EXISTS-POS #

method EXISTS-POS(\position)

Should return a Bool indicating whether the given position actually has a value.

method STORE #

method STORE(\values, :$INITIALIZE)

This method should only be supplied if you want to support the: syntax for binding your implementation of the Positional role. Should accept the values to (re-)initialize the object with. The optional named parameter will contain a True value when the method is called on the object for the first time. Should return the invocant. See Methods to implement for positional subscripting for information about additional methods that can be implemented for the Positional role.

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

1 doc-drift · 2 no-output

role Positional[::T = Mu] { ... }

Not executed: the documentation states no expected output for this example.

my @þ;
say @þ.of.^name;   # OUTPUT: «Mu␤
my Str @þð;
say @þð.of.raku;   # OUTPUT: «Str␤»
say (my int @).of; # OUTPUT: «(int)␤»
Documentation
Str
(int)
Rakudo
Mu
Str
(int)
Raku++
Mu
Str
(int)

Both engines agree; the documentation states something else. Trust the engines.

my @a is Foo = 1,2,3;

Not executed: the documentation states no expected output for this example.