Created
July 3, 2018 01:36
-
-
Save lizmat/0f8272c91cdbf37f688cf2e08231c286 to your computer and use it in GitHub Desktop.
Creating a Seq from a List of Seqs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub ListOfSeqsToSeq(**@seqs) { | |
Seq.new( class :: does Iterator { | |
has @.seqs; | |
has $!iterator; | |
method TWEAK() { $!iterator = @!seqs.shift.iterator if @!seqs } | |
method pull-one() is raw { | |
if $!iterator { | |
my $pulled := $!iterator.pull-one; | |
if $pulled =:= IterationEnd { | |
if @!seqs { | |
$!iterator = @!seqs.shift.iterator; | |
$pulled := self.pull-one; | |
} | |
else { | |
$!iterator = Nil; | |
} | |
} | |
$pulled | |
} | |
else { | |
IterationEnd | |
} | |
} | |
}.new( :@seqs ) ) | |
} | |
dd ListOfSeqsToSeq( Seq.new((1,2,3).iterator), (Seq.new((4,5,6).iterator) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment