Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the autobox-Core CPAN distribution.

Report information
The Basics
Id: 32547
Status: resolved
Priority: 0/
Queue: autobox-Core

People
Owner: Nobody in particular
Requestors: tokuhirom+cpan [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: more smart 3->times method
I want to use Show quoted text
> say $_ for 3->times;
follow is a patch. === Core.pm ================================================================== --- Core.pm (revision 7192) +++ Core.pm (local) @@ -528,7 +528,13 @@ sub downto ($$) { [ CORE::reverse $_[1]..$_[0] ] } # just weird, but cool -sub times ($&) { for (0..$_[0]-1) { $_[1]->($_); }; $_[0]; } +sub times ($;&) { + if ($_[1]) { + for (0..$_[0]-1) { $_[1]->($_); }; $_[0]; + } else { + 0..$_[0]-1 + } +} # doesn't minipulate scalars but works on scalars === t/added.t ================================================================== --- t/added.t (revision 7192) +++ t/added.t (local) @@ -1,5 +1,5 @@ use Test; -BEGIN { plan tests => 64 }; +BEGIN { plan tests => 66 }; use autobox; use autobox::Core; @@ -96,9 +96,12 @@ ok($a->[0] == 10 && $a->[@$a-1] == 1); $a = 1; -10->times(sub {$a++}); +ok(10->times(sub {$a++}) == 10); ok($a == 11); +$a = 1; +$a++ for 10->times; +ok($a == 11); ##################################################################### # Hashes
On Tue Jan 22 20:52:56 2008, TOKUHIROM wrote: Show quoted text
> I want to use
> > say $_ for 3->times;
> follow is a patch. > > === Core.pm > ================================================================== > --- Core.pm (revision 7192) > +++ Core.pm (local) > @@ -528,7 +528,13 @@ > sub downto ($$) { [ CORE::reverse $_[1]..$_[0] ] } > > # just weird, but cool > -sub times ($&) { for (0..$_[0]-1) { $_[1]->($_); }; $_[0]; } > +sub times ($;&) { > + if ($_[1]) { > + for (0..$_[0]-1) { $_[1]->($_); }; $_[0]; > + } else { > + 0..$_[0]-1 > + } > +} > > # doesn't minipulate scalars but works on scalars > > === t/added.t > ================================================================== > --- t/added.t (revision 7192) > +++ t/added.t (local) > @@ -1,5 +1,5 @@ > use Test; > -BEGIN { plan tests => 64 }; > +BEGIN { plan tests => 66 }; > use autobox; > use autobox::Core; > > @@ -96,9 +96,12 @@ > ok($a->[0] == 10 && $a->[@$a-1] == 1); > > $a = 1; > -10->times(sub {$a++}); > +ok(10->times(sub {$a++}) == 10); > ok($a == 11); > > +$a = 1; > +$a++ for 10->times; > +ok($a == 11); > > ##################################################################### > # Hashes
Applied. Thanks!