role Positional

Object that supports looking up values by index

role Positional { ... }

Role for objects which support indexing them using postcircumfix:«[ ]» (usually list-like objects). Example types with Positional role include List, Array, Range, and Buf.

Methods

method of

method of()

Returns the type constraint for elements of the positional container. Defaults to Mu.

Methods that should be provided

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:

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

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 also

See Methods to implement for positional subscripting for information about additional methods that can be implemented for the Positional role.

Type Graph

Type relations for Positional
perl6-type-graph Positional Positional Mu Mu Any Any Any->Mu Cool Cool Cool->Any Iterable Iterable List List List->Positional List->Cool List->Iterable Stringy Stringy Blob Blob Blob->Positional Blob->Stringy Range Range Range->Positional Range->Cool Range->Iterable Uni Uni Uni->Positional Uni->Any Uni->Stringy Slip Slip Slip->List Array Array Array->List NFKC NFKC NFKC->Uni NFKD NFKD NFKD->Uni NFC NFC NFC->Uni NFD NFD NFD->Uni Buf Buf Buf->Blob utf8 utf8 utf8->Any utf8->Blob

Expand above chart