method pull-one
1 | role Iterator |
1.1 | (Iterator) method pull-one |
Documentation for method pull-one
assembled from the following types:
role Iterator
From Iterator
(Iterator) method pull-one
Defined as:
method pull-one(Iterator: --> Mu)
This method stub ensures that classes implementing the Iterator
role provide a method named pull-one
.
The pull-one
method is supposed to produce and return the next value if possible, or return the sentinel value IterationEnd
if no more values could be produced.
my = (1 .. 3).iterator;say .pull-one; # OUTPUT: «1»say .pull-one; # OUTPUT: «2»say .pull-one; # OUTPUT: «3»say .pull-one.perl; # OUTPUT: «IterationEnd»
As a more illustrative example of its use, here is a count down iterator along with a simplistic subroutine re-implementation of the for
loop.
# works the same as (10 ... 1, 'lift off')does Iteratorsub for( Iterable , --> Nil )for( Seq.new(CountDown.new), ); # OUTPUT: «10987654321lift off»
It would be more idiomatic to use while
or until
, and a sigilless variable.
until IterationEnd =:= (my \pulled = .pull-one)