Skip Menu |
 

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

Report information
The Basics
Id: 8456
Status: resolved
Priority: 0/
Queue: List-MoreUtils

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

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



Subject: Add zip function?
I think it would be nice to add a zip() function to List::MoreUtils, similar to the same-named function in python. Below are two sketches how this function could be implemented. The first one is nice because it allows calling the function as zip { ... } $arr1, $arr2, ... like grep or map. The second one is nice because it allows to drop the code parameter and the probably most common operation [@_] will be used instead. Regards, Slaven use strict; use List::Util qw(min sum); sub zip (&;@) { my($sub, @arr_ref) = @_; my @res; for my $i (0 .. min map { $#$_ } @arr_ref) { push @res, $sub->(map { $arr_ref[$_][$i] } 0 .. $#arr_ref); } @res; } sub zip2 { my $sub; if (UNIVERSAL::isa($_[0], "CODE")) { $sub = shift @_; } else { $sub = sub { [@_] }; } &zip($sub, @_); } #my @res = zip { [@_] } [1,2,3,4], [qw(a b c)]; #my @res = zip2 [1,2,3,4], [qw(a b c)]; my @res = zip2 sub { sum @_ }, [1,2,3,4], [2,4,6,8]; require Data::Dumper; print STDERR "Line " . __LINE__ . ", File: " . __FILE__ . "\n" . Data::Dumper->new([\@res],[])->Indent(1)->Useqq(1)->Dump;
Date: Tue, 16 Nov 2004 15:10:29 +0100
From: Tassilo von Parseval <tassilo.von.parseval [...] rwth-aachen.de>
Subject: Re: [cpan #8456] Add zip function?
To: Slaven_Rezic via RT <bug-List-MoreUtils [...] rt.cpan.org>
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.2k
On Tue, Nov 16, 2004 at 06:52:55AM -0500 Slaven_Rezic via RT wrote: Show quoted text
> This message about List-MoreUtils was sent to you by SREZIC <SREZIC@cpan.org> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=8456 > > > I think it would be nice to add a zip() function to List::MoreUtils, > similar to the same-named function in python. Below are two sketches > how this function could be implemented. The first one is nice because > it allows calling the function as > > zip { ... } $arr1, $arr2, ... > > like grep or map. The second one is nice because it allows to drop > the code parameter and the probably most common operation [@_] will > be used instead.
Ah, yes, I see. I am right now incorporating all the missing functions from List::MoreUtil (note the missing plural 's') into List::MoreUtils. So the timing of your suggestion couldn't have been better. :-) I expect zip() and zip2() to be real pigs to implement in XS. But I think I should be done with it by the end of this week. Cheers, Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
Download (untitled) / with headers
text/plain 132b
zip() is now in 0.07 which I just uploaded. Same for zip2(), but it is named pairwise() (taken from List::MoreUtil) Cheers, Tassilo


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.