Skip Menu |

This queue is for tickets about the Iterator-Simple CPAN distribution.

Report information
The Basics
Id: 107612
Status: resolved
Priority: 0/
Queue: Iterator-Simple

People
Owner: wftk [...] vivtek.com
Requestors: keno [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.06
Fixed in: 0.07



Subject: islice bug: false values exhaust the iterator
I was using the head() method and seeing the resulting iterator stop prematurely. Turns out it stops when it sees a non-true value (such as 0). $ perl -MIterator::Simple=iter -E 'my$it=iter([1,2,3,4,5,6])->head(4); say $_ while <$it>' 1 2 3 4 $ perl -MIterator::Simple=iter -E 'my$it=iter([1,2,0,4,5,6])->head(4); say $_ while <$it>' 1 2 $ islice() is checking the truth value not definedness. Here's the patch. $ diff -u Simple.pm-old Simple.pm-new --- Simple.pm-old 2015-10-07 15:24:52.148895400 -0500 +++ Simple.pm-new 2015-10-07 15:25:03.286372900 -0500 @@ -324,7 +324,7 @@ ref($src)->new(sub{ return if $next < 0; my $rv; - while($rv = $src->()) { + while(defined($rv = $src->())) { if($idx++ == $next) { $next += $step; if($end > 0 and $next >= $end) { $