Skip Menu |
 
rt.cpan.org will be shut down on March 1st, 2021.

This queue is for tickets about the Moose-Autobox CPAN distribution.

Report information
The Basics
Id: 40040
Status: open
Priority: 0/
Queue: Moose-Autobox

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

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



Subject: Equivalent method for 'x' operator.
Download (untitled) / with headers
text/plain 354b
Getting an array to repeat is confusing. @foo x 4 doesn't dwim, it's (@foo) x 4. A repeat() method for autoboxed scalars and arrays would be handy. Called on an array, it would repeat the whole array. Called on a scalar, it would repeat the scalar. [1, 2]->repeat(2); # (1, 2, 1, 2) \"foo"->repeat(2); # "foofoo" Similar issues with reverse().
Download (untitled) / with headers
text/plain 552b
The current behavior of reverse is unfortunate. We've been making slow progress to make Scalar items act like one-element lists. That makes having distinct behavior for reverse annoying. I'd rather do something to fix that than make it worse with repeat. "the team" mostly agrees. So we want this: @array->repeat(3); # qw(a b a b a b) $string->repeat(3); # qw(foo foo foo); $string->repeat_str(3); # foofoofoo The problem is that we haven't found any method names we like for repeat and repeat_str. Suggestions are welcome. -- rjbs
Download (untitled) / with headers
text/plain 1.6k
On Sat Sep 04 22:51:55 2010, RJBS wrote: Show quoted text
> The current behavior of reverse is unfortunate. We've been making > slow progress to make > Scalar items act like one-element lists. That makes having distinct > behavior for reverse > annoying. I'd rather do something to fix that than make it worse with > repeat.
Is this something like the single element lists from Perl 6 that magically act like scalars if you use them as scalars and lists if you use them as lists? I forget what they're called, but I liked the idea and it solved a bunch of interface issues. A cleverly overloaded blessed ARRAY ref seemed to do the trick, unless you check if its blessed. Show quoted text
> "the team" mostly agrees. So we want this: > > @array->repeat(3); # qw(a b a b a b) > > $string->repeat(3); # qw(foo foo foo); > > $string->repeat_str(3); # foofoofoo > > The problem is that we haven't found any method names we like for > repeat and repeat_str.
I'd take advantage of having methods, rather than catch all keywords, and have ARRAY::repeat return an array and SCALAR::repeat return a scalar. @array->repeat(3); qw(a b a b); $string->repeat(3); "foofoofoo"; [$string]->repeat(3); qw(foo foo foo); I don't think the single-element list solution applies here because this isn't a "sometimes I expect a list and sometimes I expect a scalar" situation. I have been wanting it for things like ARRAY->pop. my $item = @array->pop; my @items = @array->pop(3); Also, you'll find you want to return refs. Why? Flattened arrays don't chain and you wind up having to mix metaphors. # If it returns a flat array say join ", ", @array->repeat(3); vs # If it returns an array ref @array->repeat(3)->join(", ")->say;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.