Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^4: [Perl6] Seq iterator already consumed

by Athanasius (Archbishop)
on Jun 19, 2019 at 06:51 UTC ( #11101544=note: print w/replies, xml ) Need Help??

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;


[("", "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.


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,

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11101544]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-09-27 17:30 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (122 votes). Check out past polls.