summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-07-03 18:34:42 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-07-03 18:34:42 +0000
commitd2850fd2cd4113aa2261dae98d4e5a32b68edca8 (patch)
tree434c283beb78d1ecd99e4f4fbab1ceacc8056e52
parent165cafb7cd81f3231ddf81a45cc5dfdb55640017 (diff)
downloadperl-MDK-Common-d2850fd2cd4113aa2261dae98d4e5a32b68edca8.tar
perl-MDK-Common-d2850fd2cd4113aa2261dae98d4e5a32b68edca8.tar.gz
perl-MDK-Common-d2850fd2cd4113aa2261dae98d4e5a32b68edca8.tar.bz2
perl-MDK-Common-d2850fd2cd4113aa2261dae98d4e5a32b68edca8.tar.xz
perl-MDK-Common-d2850fd2cd4113aa2261dae98d4e5a32b68edca8.zip
MDK/Common/Func.pm: add "partition"
-rw-r--r--MDK/Common.pm.pl2
-rw-r--r--MDK/Common/Func.pm19
-rw-r--r--perl-MDK-Common.spec5
3 files changed, 22 insertions, 4 deletions
diff --git a/MDK/Common.pm.pl b/MDK/Common.pm.pl
index 50c197e..304ea49 100644
--- a/MDK/Common.pm.pl
+++ b/MDK/Common.pm.pl
@@ -70,7 +70,7 @@ use vars qw(@ISA @EXPORT $VERSION); #);
# perl_checker: RE-EXPORT-ALL
@EXPORT = map { @$_ } map { values %{'MDK::Common::' . $_ . 'EXPORT_TAGS'} } grep { /::$/ } keys %MDK::Common::;
-$VERSION = "1.0.2";
+$VERSION = "1.0.3";
1;
EOF
diff --git a/MDK/Common/Func.pm b/MDK/Common/Func.pm
index 04a2402..bc34fce 100644
--- a/MDK/Common/Func.pm
+++ b/MDK/Common/Func.pm
@@ -100,6 +100,14 @@ returns the hash key/value for which CODE applied with $::a (key) and $::b
gives 1=>2, 4=>2
+=item partition { CODE } LIST
+
+alike C<grep>, but returns both the list of matching elements and non matching elements
+
+ my ($greater, $lower) = partition { $_ > 3 } 4, 2, 8, 0, 1
+
+gives $greater = [ 4, 8 ] and $lower = [ 2, 0, 1 ]
+
=item before_leaving { CODE }
the code will be executed when the current block is finished
@@ -141,7 +149,7 @@ use MDK::Common::Math;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(may_apply if_ if__ fold_left mapn mapn_ map_index each_index grep_index find_index map_each grep_each before_leaving catch_cdie cdie);
+@EXPORT_OK = qw(may_apply if_ if__ fold_left mapn mapn_ map_index each_index grep_index find_index map_each grep_each partition before_leaving catch_cdie cdie);
%EXPORT_TAGS = (all => [ @EXPORT_OK ]);
@@ -227,7 +235,14 @@ sub grep_each(&%) {
while (($::a, $::b) = each %h) { $l{$::a} = $::b if &$f($::a, $::b) }
%l;
}
-
+sub partition(&@) {
+ my $f = shift;
+ my (@a, @b);
+ foreach (@_) {
+ $f->($_) ? push(@a, $_) : push(@b, $_);
+ }
+ \@a, \@b;
+}
sub add_f4before_leaving {
my ($f, $b, $name) = @_;
diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec
index 9d3ff99..063f720 100644
--- a/perl-MDK-Common.spec
+++ b/perl-MDK-Common.spec
@@ -2,7 +2,7 @@
# do not change the version here, change in MDK/Common.pm.pl
%define version THEVERSION
-%define release 13mdk
+%define release 1mdk
%define perl_sitelib %(eval "`perl -V:installsitelib`"; echo $installsitelib)
Summary: Various simple functions
@@ -50,6 +50,9 @@ rm -rf $RPM_BUILD_ROOT
# MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common
%changelog
+* Wed Jul 3 2002 Pixel <pixel@mandrakesoft.com> 1.0.3-1mdk
+- MDK/Common/Func.pm: add "partition"
+
* Tue Feb 19 2002 Pixel <pixel@mandrakesoft.com> 1.0.2-13mdk
- perl_checker: skip s///