role Sequence

Common methods of sequences
role Sequence does PositionalBindFailover { }

This role implements a series of methods for converting sequences and accessing their elements. These methods should work on all sequences: serial Seq, ordered parallel HyperSeq, and unordered parallel RaceSeq.

These methods have in common that they all access the underlying iterator if the sequence has not been cached yet. Therefore they will throw an error of type X::Seq::Consumed if called on a Seq that was already consumed.

Methods

method Str

multi method Str(::?CLASS:D:)

Stringifies the cached sequence.

method Stringy

multi method Stringy(::?CLASS:D:)

Calls .Stringy on the cached sequence.

method Numeric

method Numeric(::?CLASS:D:)

Returns the number of elements in the cached sequence.

method AT-POS

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.

method EXISTS-POS

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

Returns a Bool indicating whether there is an element at position $idx in the cached sequence.

method eager

method eager(::?CLASS:D: --> List:D)

Returns an eagerly evaluated List based on the invocant sequence, and marks it as consumed. If called on an already consumed Seq, throws an error of type X::Seq::Consumed.

my $s = lazy 1..5;
say $s.is-lazy; # OUTPUT: «True␤»
    say $s.eager;   # OUTPUT: «(1 2 3 4 5)␤»
say $s.eager;
    CATCH {
        when X::Seq::Consumed {
            say 'Throws exception if already consumed';
        }
    }
    # OUTPUT: «Throws exception if already consumed␤»

method fmt

method fmt($format = '%s', $separator = ' ' --> Str:D)

Formats the cached sequence.

method gist

multi method gist(::?CLASS:D:)

Returns the gist of the cached sequence.

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 Positional

Object that supports looking up values by index

role PositionalBindFailover

Failover for binding to a Positional

role QuantHash

Object hashes with a limitation on the type of values

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.