-
-
Save ashgti/286221 to your computer and use it in GitHub Desktop.
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
# version 1 | |
sub infix:<Z>(*@@args) { | |
my @lists = @@args>>.list; | |
gather { | |
take @lists>>.shift while all(@lists); | |
} | |
} | |
# version 2 | |
# Assume Iterator has .next ("move to next element, return true/false") | |
# and .value ("give me the element you're currently on") methods. | |
# Then we have: | |
sub infix:<Z>(*@@args) { | |
my @iters = @@args>>.iterator; | |
gather { | |
while all(@iters>>.next) { take @iters>>.value; } | |
} | |
} | |
# version 3, using sentinel return from Iterator | |
sub infix:<A>(*@@args) { | |
my @iters = @@args>>.iterator; | |
gather { | |
loop { | |
my @results = @iters>>.get; | |
last if any(@results) == SENTINEL; | |
take @results; | |
} | |
} | |
} | |
# version 4, using an exception | |
sub infix:<A>(*@@args) { | |
my @iters = @@args>>.iterator; | |
gather { | |
loop { | |
my @results = @iters>>.get; | |
take @results; | |
} | |
CATCH SENTINEL { | |
last; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment