Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic, iterator-based implementation of roundrobin
passes all but one test, and is probably horribly inefficient
  • Loading branch information
moritz committed Aug 22, 2015
1 parent 7ccbe0d commit 46b97a9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/List.pm
Expand Up @@ -974,11 +974,20 @@ sub infix:<Z>(|lol) {
my &zip := &infix:<Z>;

sub roundrobin(**@lol) {
my @l = @lol.map({ (.flat,).list.item });
my @iters = @lol.map: { nqp::istype($_, Iterable) ?? .iterator !! .list.iterator };
gather {
my $p;
while $p := @l.grep(*.Bool).map(*.shift).eager.List {
take $p;
while @iters {
my @new-iters;
my @values;
for @iters -> $i {
my \v = $i.pull-one;
if v !=:= IterationEnd {
@values.push: v;
@new-iters.push: $i;
}
}
take @values if @values;
@iters = @new-iters;
}
}
}
Expand Down

0 comments on commit 46b97a9

Please sign in to comment.