develooper Front page | perl.perl6.users | Postings from January 2018

Chained sequence operators

Thread Next
From:
Sean McAfee
Date:
January 26, 2018 18:50
Subject:
Chained sequence operators
Message ID:
CANan03a3rDtPR9Qh_WM=8E3au926jhmxMURzScX3qNSd81MS-w@mail.gmail.com
Today I stumbled across the fact that the sequence operator can be chained:

> 1...5...1
(1 2 3 4 5 4 3 2 1)

You can even reduce with it:

> [...] 1, 5, 3, 10, 8
(1 2 3 4 5 4 3 4 5 6 7 8 9 10 9 8)

And even sequences with custom generators can be joined:

> 0,1,*+*...144,*/2...9
(0 1 1 2 3 5 8 13 21 34 55 89 144 72 36 18 9)

Pretty cool!  The online docs for the operator don't seem to offer even a
hint that this is possible, though.

Anyway, I was hoping that someone with more insight into the internals
could describe how this works.  Simple concatenation, or can sequences
lazily dispatch to another sequence once exhausted, or...?

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About