1251b532d278dd8e1e47fe4006c7701ccbb8f18a
[kivitendo-erp.git] / modules / fallback / List / MoreUtils.pm
1 package List::MoreUtils;
2
3 use 5.00503;
4 use strict;
5 use Exporter   ();
6 use DynaLoader ();
7
8 use vars qw{ $VERSION @ISA @EXPORT_OK %EXPORT_TAGS };
9 BEGIN {
10     $VERSION   = '0.30';
11     @ISA       = qw{ Exporter DynaLoader };
12     @EXPORT_OK = qw{
13         any all none notall true false
14         firstidx first_index lastidx last_index
15         insert_after insert_after_string
16         apply indexes
17         after after_incl before before_incl
18         firstval first_value lastval last_value
19         each_array each_arrayref
20         pairwise natatime
21         mesh zip uniq distinct
22         minmax part
23     };
24     %EXPORT_TAGS = (
25         all => \@EXPORT_OK,
26     );
27
28     # Load the XS at compile-time so that redefinition warnings will be
29     # thrown correctly if the XS versions of part or indexes loaded
30     eval {
31         # PERL_DL_NONLAZY must be false, or any errors in loading will just
32         # cause the perl code to be tested
33         local $ENV{PERL_DL_NONLAZY} = 0 if $ENV{PERL_DL_NONLAZY};
34
35         bootstrap List::MoreUtils $VERSION;
36         1;
37
38     } unless $ENV{LIST_MOREUTILS_PP};
39 }
40
41 # Always use Perl apply() until memory leaks are resolved.
42 sub apply (&@) {
43     my $action = shift;
44     &$action foreach my @values = @_;
45     wantarray ? @values : $values[-1];
46 }
47
48 # Always use Perl part() until memory leaks are resolved.
49 sub part (&@) {
50     my ($code, @list) = @_;
51     my @parts;
52     push @{ $parts[ $code->($_) ] }, $_  foreach @list;
53     return @parts;
54 }
55
56 # Always use Perl indexes() until memory leaks are resolved.
57 sub indexes (&@) {
58     my $test = shift;
59     grep {
60         local *_ = \$_[$_];
61         $test->()
62     } 0 .. $#_;
63 }
64
65 # Load the pure-Perl versions of the other functions if needed
66 eval <<'END_PERL' unless defined &any;
67
68 # Use pure scalar boolean return values for compatibility with XS
69 use constant YES => ! 0;
70 use constant NO  => ! 1;
71
72 sub any (&@) {
73     my $f = shift;
74     foreach ( @_ ) {
75         return YES if $f->();
76     }
77     return NO;
78 }
79
80 sub all (&@) {
81     my $f = shift;
82     foreach ( @_ ) {
83         return NO unless $f->();
84     }
85     return YES;
86 }
87
88 sub none (&@) {
89     my $f = shift;
90     foreach ( @_ ) {
91         return NO if $f->();
92     }
93     return YES;
94 }
95
96 sub notall (&@) {
97     my $f = shift;
98     foreach ( @_ ) {
99         return YES unless $f->();
100     }
101     return NO;
102 }
103
104 sub true (&@) {
105     my $f     = shift;
106     my $count = 0;
107     foreach ( @_ ) {
108         $count++ if $f->();
109     }
110     return $count;
111 }
112
113 sub false (&@) {
114     my $f     = shift;
115     my $count = 0;
116     foreach ( @_ ) {
117         $count++ unless $f->();
118     }
119     return $count;
120 }
121
122 sub firstidx (&@) {
123     my $f = shift;
124     foreach my $i ( 0 .. $#_ ) {
125         local *_ = \$_[$i];
126         return $i if $f->();
127     }
128     return -1;
129 }
130
131 sub lastidx (&@) {
132     my $f = shift;
133     foreach my $i ( reverse 0 .. $#_ ) {
134         local *_ = \$_[$i];
135         return $i if $f->();
136     }
137     return -1;
138 }
139
140 sub insert_after (&$\@) {
141     my ($f, $val, $list) = @_;
142     my $c = -1;
143     local *_;
144     foreach my $i ( 0 .. $#$list ) {
145         $_ = $list->[$i];
146         $c = $i, last if $f->();
147     }
148     @$list = (
149         @{$list}[ 0 .. $c ],
150         $val,
151         @{$list}[ $c + 1 .. $#$list ],
152     ) and return 1 if $c != -1;
153     return 0;
154 }
155
156 sub insert_after_string ($$\@) {
157     my ($string, $val, $list) = @_;
158     my $c = -1;
159     foreach my $i ( 0 .. $#$list ) {
160         local $^W = 0;
161         $c = $i, last if $string eq $list->[$i];
162     }
163     @$list = (
164         @{$list}[ 0 .. $c ],
165         $val,
166         @{$list}[ $c + 1 .. $#$list ],
167     ) and return 1 if $c != -1;
168     return 0;
169 }
170
171 sub after (&@) {
172     my $test = shift;
173     my $started;
174     my $lag;
175     grep $started ||= do {
176         my $x = $lag;
177         $lag = $test->();
178         $x
179     }, @_;
180 }
181
182 sub after_incl (&@) {
183     my $test = shift;
184     my $started;
185     grep $started ||= $test->(), @_;
186 }
187
188 sub before (&@) {
189     my $test = shift;
190     my $more = 1;
191     grep $more &&= ! $test->(), @_;
192 }
193
194 sub before_incl (&@) {
195     my $test = shift;
196     my $more = 1;
197     my $lag  = 1;
198     grep $more &&= do {
199         my $x = $lag;
200         $lag = ! $test->();
201         $x
202     }, @_;
203 }
204
205 sub lastval (&@) {
206     my $test = shift;
207     my $ix;
208     for ( $ix = $#_; $ix >= 0; $ix-- ) {
209         local *_ = \$_[$ix];
210         my $testval = $test->();
211
212         # Simulate $_ as alias
213         $_[$ix] = $_;
214         return $_ if $testval;
215     }
216     return undef;
217 }
218
219 sub firstval (&@) {
220     my $test = shift;
221     foreach ( @_ ) {
222         return $_ if $test->();
223     }
224     return undef;
225 }
226
227 sub pairwise (&\@\@) {
228     my $op = shift;
229
230     # Symbols for caller's input arrays
231     use vars qw{ @A @B };
232     local ( *A, *B ) = @_;
233
234     # Localise $a, $b
235     my ( $caller_a, $caller_b ) = do {
236         my $pkg = caller();
237         no strict 'refs';
238         \*{$pkg.'::a'}, \*{$pkg.'::b'};
239     };
240
241     # Loop iteration limit
242     my $limit = $#A > $#B? $#A : $#B;
243
244     # This map expression is also the return value
245     local( *$caller_a, *$caller_b );
246     map {
247         # Assign to $a, $b as refs to caller's array elements
248         ( *$caller_a, *$caller_b ) = \( $A[$_], $B[$_] );
249
250         # Perform the transformation
251         $op->();
252     }  0 .. $limit;
253 }
254
255 sub each_array (\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) {
256     return each_arrayref(@_);
257 }
258
259 sub each_arrayref {
260     my @list  = @_; # The list of references to the arrays
261     my $index = 0;  # Which one the caller will get next
262     my $max   = 0;  # Number of elements in longest array
263
264     # Get the length of the longest input array
265     foreach ( @list ) {
266         unless ( ref $_ eq 'ARRAY' ) {
267             require Carp;
268             Carp::croak("each_arrayref: argument is not an array reference\n");
269         }
270         $max = @$_ if @$_ > $max;
271     }
272
273     # Return the iterator as a closure wrt the above variables.
274     return sub {
275         if ( @_ ) {
276             my $method = shift;
277             unless ( $method eq 'index' ) {
278                 require Carp;
279                 Carp::croak("each_array: unknown argument '$method' passed to iterator.");
280             }
281
282             # Return current (last fetched) index
283             return undef if $index == 0  ||  $index > $max;
284             return $index - 1;
285         }
286
287         # No more elements to return
288         return if $index >= $max;
289         my $i = $index++;
290
291         # Return ith elements
292         return map $_->[$i], @list; 
293     }
294 }
295
296 sub natatime ($@) {
297     my $n    = shift;
298     my @list = @_;
299     return sub {
300         return splice @list, 0, $n;
301     }
302 }
303
304 sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) {
305     my $max = -1;
306     $max < $#$_ && ( $max = $#$_ ) foreach @_;
307     map {
308         my $ix = $_;
309         map $_->[$ix], @_;
310     } 0 .. $max; 
311 }
312
313 sub uniq (@) {
314     my %seen = ();
315     grep { not $seen{$_}++ } @_;
316 }
317
318 sub minmax (@) {
319     return unless @_;
320     my $min = my $max = $_[0];
321
322     for ( my $i = 1; $i < @_; $i += 2 ) {
323         if ( $_[$i-1] <= $_[$i] ) {
324             $min = $_[$i-1] if $min > $_[$i-1];
325             $max = $_[$i]   if $max < $_[$i];
326         } else {
327             $min = $_[$i]   if $min > $_[$i];
328             $max = $_[$i-1] if $max < $_[$i-1];
329         }
330     }
331
332     if ( @_ & 1 ) {
333         my $i = $#_;
334         if ($_[$i-1] <= $_[$i]) {
335             $min = $_[$i-1] if $min > $_[$i-1];
336             $max = $_[$i]   if $max < $_[$i];
337         } else {
338             $min = $_[$i]   if $min > $_[$i];
339             $max = $_[$i-1] if $max < $_[$i-1];
340         }
341     }
342
343     return ($min, $max);
344 }
345
346 sub _XScompiled {
347     return 0;
348 }
349
350 END_PERL
351 die $@ if $@;
352
353 # Function aliases
354 *first_index = \&firstidx;
355 *last_index  = \&lastidx;
356 *first_value = \&firstval;
357 *last_value  = \&lastval;
358 *zip         = \&mesh;
359 *distinct    = \&uniq;
360
361 1;
362
363 __END__
364
365 =pod
366
367 =head1 NAME
368
369 List::MoreUtils - Provide the stuff missing in List::Util
370
371 =head1 SYNOPSIS
372
373     use List::MoreUtils qw{
374         any all none notall true false
375         firstidx first_index lastidx last_index
376         insert_after insert_after_string
377         apply indexes
378         after after_incl before before_incl
379         firstval first_value lastval last_value
380         each_array each_arrayref
381         pairwise natatime
382         mesh zip uniq distinct minmax part
383     };
384
385 =head1 DESCRIPTION
386
387 B<List::MoreUtils> provides some trivial but commonly needed functionality on
388 lists which is not going to go into L<List::Util>.
389
390 All of the below functions are implementable in only a couple of lines of Perl
391 code. Using the functions from this module however should give slightly better
392 performance as everything is implemented in C. The pure-Perl implementation of
393 these functions only serves as a fallback in case the C portions of this module
394 couldn't be compiled on this machine.
395
396 =over 4
397
398 =item any BLOCK LIST
399
400 Returns a true value if any item in LIST meets the criterion given through
401 BLOCK. Sets C<$_> for each item in LIST in turn:
402
403     print "At least one value undefined"
404         if any { ! defined($_) } @list;
405
406 Returns false otherwise, or if LIST is empty.
407
408 =item all BLOCK LIST
409
410 Returns a true value if all items in LIST meet the criterion given through
411 BLOCK. Sets C<$_> for each item in LIST in turn:
412
413     print "All items defined"
414         if all { defined($_) } @list;
415
416 Returns false otherwise, or if LIST is empty.
417
418 =item none BLOCK LIST
419
420 Logically the negation of C<any>. Returns a true value if no item in LIST meets
421 the criterion given through BLOCK. Sets C<$_> for each item in LIST in turn:
422
423     print "No value defined"
424         if none { defined($_) } @list;
425
426 Returns false otherwise, or if LIST is empty.
427
428 =item notall BLOCK LIST
429
430 Logically the negation of C<all>. Returns a true value if not all items in LIST
431 meet the criterion given through BLOCK. Sets C<$_> for each item in LIST in
432 turn:
433
434     print "Not all values defined"
435         if notall { defined($_) } @list;
436
437 Returns false otherwise, or if LIST is empty.
438
439 =item true BLOCK LIST
440
441 Counts the number of elements in LIST for which the criterion in BLOCK is true.
442 Sets C<$_> for  each item in LIST in turn:
443
444     printf "%i item(s) are defined", true { defined($_) } @list;
445
446 =item false BLOCK LIST
447
448 Counts the number of elements in LIST for which the criterion in BLOCK is false.
449 Sets C<$_> for each item in LIST in turn:
450
451     printf "%i item(s) are not defined", false { defined($_) } @list;
452
453 =item firstidx BLOCK LIST
454
455 =item first_index BLOCK LIST
456
457 Returns the index of the first element in LIST for which the criterion in BLOCK
458 is true. Sets C<$_> for each item in LIST in turn:
459
460     my @list = (1, 4, 3, 2, 4, 6);
461     printf "item with index %i in list is 4", firstidx { $_ == 4 } @list;
462     __END__
463     item with index 1 in list is 4
464     
465 Returns C<-1> if no such item could be found.
466
467 C<first_index> is an alias for C<firstidx>.
468
469 =item lastidx BLOCK LIST
470
471 =item last_index BLOCK LIST
472
473 Returns the index of the last element in LIST for which the criterion in BLOCK
474 is true. Sets C<$_> for each item in LIST in turn:
475
476     my @list = (1, 4, 3, 2, 4, 6);
477     printf "item with index %i in list is 4", lastidx { $_ == 4 } @list;
478     __END__
479     item with index 4 in list is 4
480
481 Returns C<-1> if no such item could be found.
482
483 C<last_index> is an alias for C<lastidx>.
484
485 =item insert_after BLOCK VALUE LIST
486
487 Inserts VALUE after the first item in LIST for which the criterion in BLOCK is
488 true. Sets C<$_> for each item in LIST in turn.
489
490     my @list = qw/This is a list/;
491     insert_after { $_ eq "a" } "longer" => @list;
492     print "@list";
493     __END__
494     This is a longer list
495
496 =item insert_after_string STRING VALUE LIST
497
498 Inserts VALUE after the first item in LIST which is equal to STRING. 
499
500     my @list = qw/This is a list/;
501     insert_after_string "a", "longer" => @list;
502     print "@list";
503     __END__
504     This is a longer list
505
506 =item apply BLOCK LIST
507
508 Applies BLOCK to each item in LIST and returns a list of the values after BLOCK
509 has been applied. In scalar context, the last element is returned.  This
510 function is similar to C<map> but will not modify the elements of the input
511 list:
512
513     my @list = (1 .. 4);
514     my @mult = apply { $_ *= 2 } @list;
515     print "\@list = @list\n";
516     print "\@mult = @mult\n";
517     __END__
518     @list = 1 2 3 4
519     @mult = 2 4 6 8
520
521 Think of it as syntactic sugar for
522
523     for (my @mult = @list) { $_ *= 2 }
524
525 =item before BLOCK LIST
526
527 Returns a list of values of LIST upto (and not including) the point where BLOCK
528 returns a true value. Sets C<$_> for each element in LIST in turn.
529
530 =item before_incl BLOCK LIST
531
532 Same as C<before> but also includes the element for which BLOCK is true.
533
534 =item after BLOCK LIST
535
536 Returns a list of the values of LIST after (and not including) the point
537 where BLOCK returns a true value. Sets C<$_> for each element in LIST in turn.
538
539     @x = after { $_ % 5 == 0 } (1..9);    # returns 6, 7, 8, 9
540
541 =item after_incl BLOCK LIST
542
543 Same as C<after> but also inclues the element for which BLOCK is true.
544
545 =item indexes BLOCK LIST
546
547 Evaluates BLOCK for each element in LIST (assigned to C<$_>) and returns a list
548 of the indices of those elements for which BLOCK returned a true value. This is
549 just like C<grep> only that it returns indices instead of values:
550
551     @x = indexes { $_ % 2 == 0 } (1..10);   # returns 1, 3, 5, 7, 9
552
553 =item firstval BLOCK LIST
554
555 =item first_value BLOCK LIST
556
557 Returns the first element in LIST for which BLOCK evaluates to true. Each
558 element of LIST is set to C<$_> in turn. Returns C<undef> if no such element
559 has been found.
560
561 C<first_val> is an alias for C<firstval>.
562
563 =item lastval BLOCK LIST
564
565 =item last_value BLOCK LIST
566
567 Returns the last value in LIST for which BLOCK evaluates to true. Each element
568 of LIST is set to C<$_> in turn. Returns C<undef> if no such element has been
569 found.
570
571 C<last_val> is an alias for C<lastval>.
572
573 =item pairwise BLOCK ARRAY1 ARRAY2
574
575 Evaluates BLOCK for each pair of elements in ARRAY1 and ARRAY2 and returns a
576 new list consisting of BLOCK's return values. The two elements are set to C<$a>
577 and C<$b>.  Note that those two are aliases to the original value so changing
578 them will modify the input arrays.
579
580     @a = (1 .. 5);
581     @b = (11 .. 15);
582     @x = pairwise { $a + $b } @a, @b;   # returns 12, 14, 16, 18, 20
583
584     # mesh with pairwise
585     @a = qw/a b c/;
586     @b = qw/1 2 3/;
587     @x = pairwise { ($a, $b) } @a, @b;  # returns a, 1, b, 2, c, 3
588
589 =item each_array ARRAY1 ARRAY2 ...
590
591 Creates an array iterator to return the elements of the list of arrays ARRAY1,
592 ARRAY2 throughout ARRAYn in turn.  That is, the first time it is called, it
593 returns the first element of each array.  The next time, it returns the second
594 elements.  And so on, until all elements are exhausted.
595
596 This is useful for looping over more than one array at once:
597
598     my $ea = each_array(@a, @b, @c);
599     while ( my ($a, $b, $c) = $ea->() )   { .... }
600
601 The iterator returns the empty list when it reached the end of all arrays.
602
603 If the iterator is passed an argument of 'C<index>', then it retuns
604 the index of the last fetched set of values, as a scalar.
605
606 =item each_arrayref LIST
607
608 Like each_array, but the arguments are references to arrays, not the
609 plain arrays.
610
611 =item natatime BLOCK LIST
612
613 Creates an array iterator, for looping over an array in chunks of
614 C<$n> items at a time.  (n at a time, get it?).  An example is
615 probably a better explanation than I could give in words.
616
617 Example:
618
619     my @x = ('a' .. 'g');
620     my $it = natatime 3, @x;
621     while (my @vals = $it->())
622     {
623         print "@vals\n";
624     }
625
626 This prints
627
628     a b c
629     d e f
630     g
631
632 =item mesh ARRAY1 ARRAY2 [ ARRAY3 ... ]
633
634 =item zip ARRAY1 ARRAY2 [ ARRAY3 ... ]
635
636 Returns a list consisting of the first elements of each array, then
637 the second, then the third, etc, until all arrays are exhausted.
638
639 Examples:
640
641     @x = qw/a b c d/;
642     @y = qw/1 2 3 4/;
643     @z = mesh @x, @y;       # returns a, 1, b, 2, c, 3, d, 4
644
645     @a = ('x');
646     @b = ('1', '2');
647     @c = qw/zip zap zot/;
648     @d = mesh @a, @b, @c;   # x, 1, zip, undef, 2, zap, undef, undef, zot
649
650 C<zip> is an alias for C<mesh>.
651
652 =item uniq LIST
653
654 =item distinct LIST
655
656 Returns a new list by stripping duplicate values in LIST. The order of
657 elements in the returned list is the same as in LIST. In scalar context,
658 returns the number of unique elements in LIST.
659
660     my @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4
661     my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5
662
663 =item minmax LIST
664
665 Calculates the minimum and maximum of LIST and returns a two element list with
666 the first element being the minimum and the second the maximum. Returns the
667 empty list if LIST was empty.
668
669 The C<minmax> algorithm differs from a naive iteration over the list where each
670 element is compared to two values being the so far calculated min and max value
671 in that it only requires 3n/2 - 2 comparisons. Thus it is the most efficient
672 possible algorithm.
673
674 However, the Perl implementation of it has some overhead simply due to the fact
675 that there are more lines of Perl code involved. Therefore, LIST needs to be
676 fairly big in order for C<minmax> to win over a naive implementation. This
677 limitation does not apply to the XS version.
678
679 =item part BLOCK LIST
680
681 Partitions LIST based on the return value of BLOCK which denotes into which
682 partition the current value is put.
683
684 Returns a list of the partitions thusly created. Each partition created is a
685 reference to an array.
686
687     my $i = 0;
688     my @part = part { $i++ % 2 } 1 .. 8;   # returns [1, 3, 5, 7], [2, 4, 6, 8]
689
690 You can have a sparse list of partitions as well where non-set partitions will
691 be undef:
692
693     my @part = part { 2 } 1 .. 10;          # returns undef, undef, [ 1 .. 10 ]
694
695 Be careful with negative values, though:
696
697     my @part = part { -1 } 1 .. 10;
698     __END__
699     Modification of non-creatable array value attempted, subscript -1 ...
700
701 Negative values are only ok when they refer to a partition previously created:
702
703     my @idx  = ( 0, 1, -1 );
704     my $i    = 0;
705     my @part = part { $idx[$++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8]
706
707 =back
708
709 =head1 EXPORTS
710
711 Nothing by default. To import all of this module's symbols, do the conventional
712
713     use List::MoreUtils ':all';
714
715 It may make more sense though to only import the stuff your program actually
716 needs:
717
718     use List::MoreUtils qw{ any firstidx };
719
720 =head1 ENVIRONMENT
721
722 When C<LIST_MOREUTILS_PP> is set, the module will always use the pure-Perl
723 implementation and not the XS one. This environment variable is really just
724 there for the test-suite to force testing the Perl implementation, and possibly
725 for reporting of bugs. I don't see any reason to use it in a production
726 environment.
727
728 =head1 BUGS
729
730 There is a problem with a bug in 5.6.x perls. It is a syntax error to write
731 things like:
732
733     my @x = apply { s/foo/bar/ } qw{ foo bar baz };
734
735 It has to be written as either
736
737     my @x = apply { s/foo/bar/ } 'foo', 'bar', 'baz';
738
739 or
740
741     my @x = apply { s/foo/bar/ } my @dummy = qw/foo bar baz/;
742
743 Perl 5.5.x and Perl 5.8.x don't suffer from this limitation.
744
745 If you have a functionality that you could imagine being in this module, please
746 drop me a line. This module's policy will be less strict than L<List::Util>'s
747 when it comes to additions as it isn't a core module.
748
749 When you report bugs, it would be nice if you could additionally give me the
750 output of your program with the environment variable C<LIST_MOREUTILS_PP> set
751 to a true value. That way I know where to look for the problem (in XS,
752 pure-Perl or possibly both).
753
754 =head1 SUPPORT
755
756 Bugs should always be submitted via the CPAN bug tracker.
757
758 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=List-MoreUtils>
759
760 =head1 THANKS
761
762 Credits go to a number of people: Steve Purkis for giving me namespace advice
763 and James Keenan and Terrence Branno for their effort of keeping the CPAN
764 tidier by making L<List::Utils> obsolete. 
765
766 Brian McCauley suggested the inclusion of apply() and provided the pure-Perl
767 implementation for it.
768
769 Eric J. Roode asked me to add all functions from his module C<List::MoreUtil>
770 into this one. With minor modifications, the pure-Perl implementations of those
771 are by him.
772
773 The bunch of people who almost immediately pointed out the many problems with
774 the glitchy 0.07 release (Slaven Rezic, Ron Savage, CPAN testers).
775
776 A particularly nasty memory leak was spotted by Thomas A. Lowery.
777
778 Lars Thegler made me aware of problems with older Perl versions.
779
780 Anno Siegel de-orphaned each_arrayref().
781
782 David Filmer made me aware of a problem in each_arrayref that could ultimately
783 lead to a segfault.
784
785 Ricardo Signes suggested the inclusion of part() and provided the
786 Perl-implementation.
787
788 Robin Huston kindly fixed a bug in perl's MULTICALL API to make the
789 XS-implementation of part() work.
790
791 =head1 TODO
792
793 A pile of requests from other people is still pending further processing in
794 my mailbox. This includes:
795
796 =over 4
797
798 =item * List::Util export pass-through
799
800 Allow B<List::MoreUtils> to pass-through the regular L<List::Util>
801 functions to end users only need to C<use> the one module.
802
803 =item * uniq_by(&@)
804
805 Use code-reference to extract a key based on which the uniqueness is
806 determined. Suggested by Aaron Crane.
807
808 =item * delete_index
809
810 =item * random_item
811
812 =item * random_item_delete_index
813
814 =item * list_diff_hash
815
816 =item * list_diff_inboth
817
818 =item * list_diff_infirst
819
820 =item * list_diff_insecond
821
822 These were all suggested by Dan Muey.
823
824 =item * listify
825
826 Always return a flat list when either a simple scalar value was passed or an
827 array-reference. Suggested by Mark Summersault.
828
829 =back
830
831 =head1 SEE ALSO
832
833 L<List::Util>
834
835 =head1 AUTHOR
836
837 Tassilo von Parseval E<lt>tassilo.von.parseval@rwth-aachen.deE<gt>
838
839 =head1 COPYRIGHT AND LICENSE
840
841 Copyright 2004 - 2010 by Tassilo von Parseval
842
843 This library is free software; you can redistribute it and/or modify
844 it under the same terms as Perl itself, either Perl version 5.8.4 or,
845 at your option, any later version of Perl 5 you may have available.
846
847 =cut