Description | A static content generator. |
Newcomen::Util::List - List related utility functions.
use Newcomen::Util::List; # Create a list with all elements of the source list doubled: my @doubled = Newcomen::Util::List::dbl (@list); # Zip two lists: my @zipped = Newcomen::Util::List::zip (@list_1, @list_2);
This package provides a few utility functions dealing with lists. Note that all functions may be imported into the package using Newcomen::Util::List:
use Newcomen::Util::List qw( dbl zip );
No function is exported by default.
Toggle source: dbl
sub dbl { map { ($_) x 2 } @_ }
my @doubled = dbl (@list);
Returns a list that contains all elements of the input list twice, i.e. if the input list is
(1, 2, 3)
, the resulting list will be (1, 1, 2, 2, 3, 3)
.
Toggle source: zip
sub zip { @_ [map { $_, $_ + @_ / 2 } 0 .. (@_ / 2 - 1)] }
my @zipped = zip (@list_1, @list_2);
Zips the two input lists. For example, zipping the lists ('a', 'b', 'c')
and (1, 2, 3)
will
result in the list ('a', 1, 'b', 2, 'c', 3)
.
This is version 2014052501
.
Stefan Goebel - newcomen {at} subtype {dot} de
Copyright 2013-2014 Stefan Goebel.
This file is part of Newcomen.
Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.
Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.