Skip to content

Instantly share code, notes, and snippets.

@pmichaud
Created January 25, 2010 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pmichaud/286214 to your computer and use it in GitHub Desktop.
Save pmichaud/286214 to your computer and use it in GitHub Desktop.
# 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