Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix iterable.first(:end) on uncached iterators
.elems determines number of elements on an iterator without caching.
Prefix + caches the iterator.  The use of .elems caused:

  say "㊤".uniname.words.first(:end)

to fail.  ZoffixW++ for spotting
  • Loading branch information
lizmat committed Feb 20, 2016
1 parent e401eeb commit 8fdaada
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog
Expand Up @@ -12,6 +12,7 @@ New in 2016.02
+ Specifying ::a now gives proper compile time error (RT #127504)
+ Rakudo jars are now installed in the proper location
+ Enums with a type object now fail with an NYI error
+ .first(:end) on uncached iterators no longer fails
+ Additions:
+ Buf.unshift/Buf.prepend
+ DateTime.new(y,mo,d,h,mi,s) fully positional candidate
Expand Down
8 changes: 4 additions & 4 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -698,15 +698,15 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
proto method first(|) is nodal { * }
multi method first(:$end) {
$end
?? ((my $elems = self.elems) ?? self.AT-POS($elems - 1) !! Nil)
?? ((my $elems = +self) ?? self.AT-POS($elems - 1) !! Nil)
!! ((my $x := self.iterator.pull-one) =:= IterationEnd ?? Nil !! $x)
}
multi method first(Bool:D $t) {
fail X::Match::Bool.new( type => '.first' );
}
multi method first(Regex:D $test, :$end, *%a) is raw {
if $end {
my $elems = self.elems;
my $elems = +self;
if $elems && !($elems == Inf) {
my int $index = $elems;
return self!first-result($index,$_,'first :end',%a)
Expand All @@ -727,7 +727,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
}
multi method first(Callable:D $test, :$end, *%a is copy) is raw {
if $end {
my $elems = self.elems;
my $elems = +self;
if $elems && !($elems == Inf) {
my int $index = $elems;
return self!first-result($index,$_,'first :end',%a)
Expand All @@ -748,7 +748,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
}
multi method first(Mu $test, :$end, *%a) is raw {
if $end {
my $elems = self.elems;
my $elems = +self;
if $elems && !($elems == Inf) {
my int $index = $elems;
return self!first-result($index,$_,'first :end',%a)
Expand Down

0 comments on commit 8fdaada

Please sign in to comment.