The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

List::MapList - map lists through a list of subs, not just one

VERSION

version 1.123

SYNOPSIS

Contrived heterogenous transform

 use List::MapList;

 my $code = [
   sub { $_ + 1 },
   sub { $_ + 2 },
   sub { $_ + 3 },
   sub { $_ + 4 }
 ];

 my @mapped_1 = maplist( $code, qw(1 2 3 4 5 6 7 8 9));
 # @mapped_1 is qw(2 4 6 8)

 my @mapped_2 = mapcycle( $code, qw(1 2 3 4 5 6 7 8 9));
 # @mapped_2 is qw(2 4 6 8 6 8 10 12 13)

Ultra-secure partial rot13:

 my $rotsome = [
  sub { tr/a-zA-Z/n-za-mN-ZA-M/; $_ },
  sub { tr/a-zA-Z/n-za-mN-ZA-M/; $_ },
  sub { $_ },
 ];

 my $plaintext  = "Too many secrets.";
 my $cyphertext = join '', mapcycle($rotsome, split //, $plaintext);

DESCRIPTION

List::MapList provides methods to map a list through a list of transformations, instead of just one. The transformations are not chained together on each element; only one is used, alternating sequentially.

Here's a contrived example: given the transformations { $_ = 0 } and { $_ = 1 }, the list (1, 2, 3, "Good morning", undef) would become (0, 1, 0, 1, 0) or, without cycling, (0, 1).;

(I use this code to process a part number in which each digit maps to a set of product attributes.)

FUNCTIONS

maplist

  my @results = maplist(\@coderefs, LIST);

This routine acts much like a normal map, but uses the list of code references in $coderefs in parallel with the list members. First first code reference is used for the first list member, the next for the second, and so on. Once the last code reference has been used, all further elements will be mapped to ().

mapcycle

  my @results = mapcycle($coderefs, LIST);

This routine is identical to maplist, but will cycle through the passed coderefs over and over as needed.

AUTHOR

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2004 by Ricardo SIGNES.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.