I think this is a basic misunderstanding about what an Iterator is and what a 
Seq.

The basic thing is the Iterator.

.Seq is nothing but method Seq() { Seq.new(self.iterator) }

In other words, a Seq is just a wrapper around an Iterator.

In general, you shouldn’t be asking a Seq for its Iterator.  You could argue 
that is something that is only done internally to make things work(tm).

Also, unless you’re writing iterators yourself, you should never even need to 
know about iterators.  So I’m wondering what you’re trying to achieve.

If you change the code to:

    my $thing = (1,3,4); $thing.iterator; $thing.iterator

it would just give you two iterators.  Each iterating over the whole list.  Not 
sure if that’s what you wanted to do, but that cannot be determined from the 
code provided.

Also, I’m not sure how we can improve the error message: most Seq’s are created 
inside the core setting.  And when the “already consumed” error occurs, it’s 
going to be hard to find out where that Seq got created.

So I would categorize this bug as a DIHWIDT

> On 25 Jan 2017, at 08:15, Samantha McVey (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Samantha McVey 
> # Please include the string:  [perl #130638]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=130638 >
> 
> 
> CODE:
> my Seq $thing = (1,3,4).Seq; $thing.iterator; $thing.iterator
> 
> STDERR:
> This Seq has already been iterated, and its values consumed
> (you might solve this by adding .cache on usages of the Seq, or
> by assigning the Seq into an array)
>  in block <unit> at <unknown file> line 1
> 
> I have had lines that have multiple sequences on that, and it is very 
> difficult to know which Seq it was without a nice error.

Reply via email to