Skip to content

Commit

Permalink
1..* ... 5 and @fib ... 8 (where @fib is infinite lazy) now work
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickas committed Sep 9, 2010
1 parent c6e6807 commit 9f204b1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/operators.pm
Expand Up @@ -374,16 +374,16 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) {
}

my sub infinite-series (@lhs, $limit ) {
my $next = get-next-closure(@lhs , $limit );

gather {
for 0..^(@lhs.elems - 1) -> $i { take @lhs[$i]; }
take @lhs[*-1] unless @lhs[*-1] ~~ Code;
my $i = 0;
while @lhs[$i+1].defined { take @lhs[$i]; $i++; } #We blindly take all elems of the LHS except last one.
take @lhs[$i] unless @lhs[$i] ~~ Code; #We don't take the last element if it is code because it will be used as $next closure

my $next = get-next-closure(@lhs , $limit );
my $arity = $next.count;
my @args=@lhs;
my @args=@lhs; #TODO: maybe avoid copying the whole array into args
pop @args if @args[*-1] ~~ Code;
@args.munch( @args.elems - $arity ); #We make sure there are $arity elems
@args.munch( @args.elems - $arity ); #We make sure there are $arity elems in args

loop { #Then we extrapolate using $next and the $args
my $current = $next.(|@args) // last;
Expand Down

0 comments on commit 9f204b1

Please sign in to comment.