role Positional

Object that supports looking up values by index
role Positional[::T = Mu] { ... }

Role for objects which support indexing them using the [ ] postcircumfix operator (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, that is, the T in the definition above, which, as it can be seen, defaults to Mu. It is returned as a type object.

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

Methods that should be provided by classes that mix in this role

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.

See Also

role Associative

Object that supports looking up values by key

role Baggy

Collection of distinct weighted objects

role Blob

Immutable buffer for binary data ('Binary Large OBject')

role Buf

Mutable buffer for binary data

role Iterable

Interface for container objects that can be iterated over

role Iterator

Generic API for producing a sequence of values

role Mixy

Collection of distinct objects with Real weights

role PositionalBindFailover

Failover for binding to a Positional

role QuantHash

Object hashes with a limitation on the type of values

role Sequence

Common methods of sequences

role Setty

Collection of distinct objects

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.