How can I create a lazy list from an object?

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 = $;
        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.

- Flavio S. Glock

Reply via email to