Documentation for method
pull-one assembled from the following types:
method pull-one(Iterator: --> Mu)
This method stub ensures that classes implementing the
Iterator role provide a method named
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
# works the same as (10 ... 1, 'lift off')does Iteratorsub for( Iterable , --> Nil )for( Seq.new(CountDown.new), ); # OUTPUT: «10␤9␤8␤7␤6␤5␤4␤3␤2␤1␤lift off␤»
It would be more idiomatic to use
until, and a sigilless variable.
until IterationEnd =:= (my \pulled = .pull-one)