Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 17251
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

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

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



Subject: first_map
I found myself writing this today: use List::Utils qw(first); sort { first { $_ } map { $a->[$_] cmp $b->[$_] } @order_by_indexes } @rows; which is the equivalent of sort { $a->[$order_by_indexes[0]] cmp $a->[$order_by_indexes[0]] || $a->[$order_by_indexes[1]] cmp $b->[$order_by_indexes[1]] || ... } @rows; but its less efficient because there's no short-circuit. It does all the comparisons whether they're needed or not. It would be nice if there was a function like first() except instead of returning the first element for which the block returns true it would return the result of that first true block. In short, a first() for map instead of grep. first_map() seems the obvious name. If you like the idea, I'll code up an implementation.
Subject: Re: [rt.cpan.org #17251] first_map
Date: Tue, 24 Jan 2006 16:43:01 -0600
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
On Jan 24, 2006, at 2:14 PM, Michael_G_Schwern via RT wrote: Show quoted text
> I found myself writing this today: > > use List::Utils qw(first); > > sort { > first { $_ } > map { $a->[$_] cmp $b->[$_] } @order_by_indexes > } @rows;
This seems to be very specific to whatever it is you are doing. I do not see a general application or that it would be used much, so I am reluctant to add it Graham.
Subject: Re: [rt.cpan.org #17251] first_map
Date: Wed, 25 Jan 2006 02:48:32 -0800
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Michael G Schwern <schwern [...] gmail.com>
On 1/24/06, Graham Barr via RT <bug-Scalar-List-Utils@rt.cpan.org> wrote: Show quoted text
> > On Jan 24, 2006, at 2:14 PM, Michael_G_Schwern via RT wrote:
> > I found myself writing this today: > > > > use List::Utils qw(first); > > > > sort { > > first { $_ } > > map { $a->[$_] cmp $b->[$_] } @order_by_indexes > > } @rows;
> > This seems to be very specific to whatever it is you are doing. I do > not see a general application or that it would be used much, so I am > reluctant to add it
Just to make sure its clear, I don't mean the entire thing above with the sort and all. Its just this: sub first_map (&@) { my $code = shift; my $return; for (@_) { $return = $code->(); return $return if $return; } return $return; }
On Wed Jan 25 05:49:39 2006, schwern@pobox.com wrote: Show quoted text
> On 1/24/06, Graham Barr via RT <bug-Scalar-List-Utils@rt.cpan.org> wrote:
> > > > On Jan 24, 2006, at 2:14 PM, Michael_G_Schwern via RT wrote:
> > > I found myself writing this today: > > > > > > use List::Utils qw(first); > > > > > > sort { > > > first { $_ } > > > map { $a->[$_] cmp $b->[$_] } @order_by_indexes > > > } @rows;
> > > > This seems to be very specific to whatever it is you are doing. I do > > not see a general application or that it would be used much, so I am > > reluctant to add it
> > > Just to make sure its clear, I don't mean the entire thing above with the > sort and all. Its just this: > > sub first_map (&@) { > my $code = shift; > > my $return; > for (@_) { > $return = $code->(); > return $return if $return; > } > > return $return; > }
It seems that this is already implemented as firstval in List::MoreUtils. So close this ticket? Regards, Slaven
Subject: Re: [rt.cpan.org #17251] first_map
Date: Sun, 17 Feb 2008 10:43:13 -0800
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Slaven_Rezic via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=17251 > > > On Wed Jan 25 05:49:39 2006, schwern@pobox.com wrote:
>> On 1/24/06, Graham Barr via RT <bug-Scalar-List-Utils@rt.cpan.org> wrote:
>>> On Jan 24, 2006, at 2:14 PM, Michael_G_Schwern via RT wrote:
>>>> I found myself writing this today: >>>> >>>> use List::Utils qw(first); >>>> >>>> sort { >>>> first { $_ } >>>> map { $a->[$_] cmp $b->[$_] } @order_by_indexes >>>> } @rows;
>>> This seems to be very specific to whatever it is you are doing. I do >>> not see a general application or that it would be used much, so I am >>> reluctant to add it
>> >> Just to make sure its clear, I don't mean the entire thing above with the >> sort and all. Its just this: >> >> sub first_map (&@) { >> my $code = shift; >> >> my $return; >> for (@_) { >> $return = $code->(); >> return $return if $return; >> } >> >> return $return; >> }
> > > It seems that this is already implemented as firstval in > List::MoreUtils. So close this ticket?
Yep, that would seem to be it. -- ROCKS FALL! EVERYONE DIES! http://www.somethingpositive.net/sp05032002.shtml