Alexey Trofimenko writes:
> of course, I just mutter.. new C<for> is very good, and in special
> cases, when simple incrementing-decrementing isn't what I want, I can
> write my own iterator (btw, in which apocalypse I can find how to
> write iterators in perl6?) with my own custom very special increment
> and end condition.
You want a C<next> method, and you want the <> operator to do the right
thing in its various contexts. I presume there will be a
close-to-builtin role C<iterator> that does just that:
class MyIterator {
does iterator;
has $.count = 0;
sub next () {
$.count++;
}
}
my $iter = MyIterator.new;
say for <$iter>; # 0 1 2 3 4 5 6 ...
Luke