Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sequence operator supports limit functions with arity > 1
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
dwhipp authored and moritz committed Feb 25, 2011
1 parent 58e40e0 commit 1170a59
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/core/operators.pm
Expand Up @@ -401,16 +401,30 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) {
my $limit = ($rhs ~~ Whatever ?? Any !! $rhs);
return infinite-series(@lhs , $limit) if $rhs ~~ Whatever; #shortcut infinite series so we avoid the comparisions

fail ('Limit arity cannot be larger than 1') if $limit ~~ Code && $limit.count > 1;
#fail ('Limit arity cannot be larger than 1') if $limit ~~ Code && $limit.count > 1;
my $series = infinite-series(@lhs , $limit);

gather {
while $series {
my $val = $series.shift();
if $val ~~ $limit {
take $val unless $exclude-limit ;
last ;
};
take $val;
if $limit ~~ Code && $limit.count > 1 {
my @limit-args;
while $series {
@limit-args.shift if @limit-args == $limit.count;
my $val = $series.shift;
@limit-args.push($val);
my $done = @limit-args >= $limit.arity && $limit(|@limit-args);
take $val unless $done && $exclude-limit;
last if $done;
}
}
else {
while $series {
my $val = $series.shift();
if $val ~~ $limit {
take $val unless $exclude-limit ;
last ;
};
take $val;
}
}
}
}
Expand Down

0 comments on commit 1170a59

Please sign in to comment.