in reply to Re^3: [Perl6] Seq iterator already consumed
in thread [Perl6] Seq iterator already consumed

Hello Dean,

Thanks for this explanation! I apologise for not replying sooner, but I wanted to look at the whole question with a fresh pair of eyes first. You are absolutely right:

my @dirs.push: $_.split('/') for @paths; say @dirs.perl;

shows:

[("", "aardvark", "bison", "camel", "dromedary").Seq, ("", "aardvark", + "bison", "camel", "dromedary", "elephant").Seq]

(i.e., 2 unconsumed Seq objects), but with .cache added to the split they are Lists:

[("", "aardvark", "bison", "camel", "dromedary"), ("", "aardvark", "bi +son", "camel", "dromedary", "elephant")]

— and therefore can be iterated as often as needed.

Update:

upon consideration, using .cache may be more efficient since it is lazy

Where is this documented?

Thanks again,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^5: [Perl6] Seq iterator already consumed
by duelafn (Parson) on Jun 20, 2019 at 03:36 UTC

    Again, the documentation for Seq:

    A Seq represents anything that can lazily produce a sequence of values. A Seq is born in a state where iterating it will consume the values. However, calling .cache on a Seq will return a List that is still lazy, but stores the generated values for later access.

    Good Day,
        Dean