I have an object representing the sequence "1..Inf".
I tried creating a Coroutine, and then assigning the Coroutine to an
Array, but it only yielded "1":
my @a = $span.lazy; # "1"
The coroutine worked fine in a "while" loop, but it didn't work in a "for" loop.
This is the implementation (in "ext/Span"):
coro lazy ($self: ) {
my $iter = $self.iterator();
loop {
my $n = $iter.next;
return unless defined $n;
yield $n;
}
}
I understand that this is not fully specified yet, but I'd like to
start writing some tests for it.
Thanks!
- Flavio S. Glock
I think unary = is what you want:
my @a = $span.lazy;
for =@a -> $item {
...
}
Ofcourse, my @a = $span.lazy will have to be fixed, but what you
tried should be working.
--
() Yuval Kogman <nothi...@woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: *shu*rik*en*sh*u*rik*en*s*hur*i*ke*n*: neeyah!!!!
Is "for =" only for filehandles? I tried:
pugs> say for =1
*** cannot cast from VInt 1 to Handle (VHandle)
- Flavio S. Glock
No, it's for anything that supports iteration... `=$foo` ==
`$foo.next()`, if I recall correctly. It's probably not yet
implemented.
Aankhen
- Flavio
2005/7/29, Aankhen <aan...@gmail.com>: