Created
January 25, 2010 20:31
-
-
Save pmichaud/286214 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:<Z>(*@@args) { | |
my @iters = @@args>>.iterator; | |
gather { | |
loop { | |
my @results = @iters>>.get; | |
last if any(@results) == SENTINEL; | |
take @results; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment