PositionalBindFailover Reference
Failover for binding to a Positional
What it is #
Position in the hierarchy #
| Inherits from | — |
| Does | — |
| Consumed by | Sequence |
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 cache #
method cache(PositionalBindFailover:D: --> List:D)
Returns List:D.
Returns a List based on the iterator method, and caches it. Subsequent calls to cache always return the same List object.
method list #
multi method list(::?CLASS:D:)
Returns a List based on the iterator method without caching it.
method iterator #
method iterator(PositionalBindFailover:D:) { ... }
This method stub ensure that a class implementing role PositionalBindFailover provides an iterator method.
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.
2 no-output · 1 not-runnable · 1 ok
role PositionalBindFailover { ... }Not executed: the documentation states no expected output for this example.
sub fifths(@a) { # @a is constraint to Positional
@a[4];
}
my $seq := gather { # a Seq, which is not Positional
take $_ for 1..*;
}
say fifths($seq); # OUTPUT: «5»5
Documentation, Rakudo and Raku++ all agree.
class Foo does PositionalBindFailover {
method iterator {
class :: does Iterator {
method pull-one {
return 42 unless $++;
IterationEnd
}
}.new
}
}Not executed: the documentation states no expected output for this example.
sub first-five (@a) { @a[^5].say }
first-five Foo.new; # OUTPUT: # OUTPUT: «(42 Nil Nil Nil Nil)»Neither engine can run this in isolation — the example depends on context from the surrounding text.