Skip to content

Commit 74d13d0

Browse files
committed
Better upfront docs about zip/mesh's handling of gaps in input; further docs reärrangement about the _shortest / _longest variants
1 parent fbabeaf commit 74d13d0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/List/Util.pm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ I<Since version TODO.>
662662
663663
Returns a list of array references, composed of elements from the given list
664664
of array references. Each array in the returned list is composed of elements
665-
at that corresponding position from each of the given input arrays.
665+
at that corresponding position from each of the given input arrays. If any
666+
input arrays run out of elements before others, then C<undef> will be inserted
667+
into the result to fill in the gaps.
666668
667669
The C<zip> function is particularly handy for iterating over multiple arrays
668670
at the same time with a C<foreach> loop, taking one element from each:
@@ -680,16 +682,17 @@ so make sure to invoke it with references to arrays.
680682
For a function similar to the C<zip> function from C<List::MoreUtils>, see
681683
L<mesh>.
682684
683-
my @result = zip_longest ...
684685
my @result = zip_shortest ...
685686
686-
These different variations of the function differ in how they behave when
687-
given input arrays of differing lengths. C<zip_longest> will continue while
688-
any of the inputs still have elements, inserting C<undef> into the result if
689-
some input arrays have already run out. C<zip_shortest> will stop as soon as
690-
the shortest input runs out of elements, discarding any unused ones.
687+
A variation of the function that differs in how it behaves when given input
688+
arrays of differing lengths. C<zip_shortest> will stop as soon as any one of
689+
the input arrays run out of elements, discarding any remaining unused values
690+
from the others.
691+
692+
my @result = zip_longest ...
691693
692-
The plain C<zip> function is an alias to C<zip_longest>.
694+
C<zip_longest> is an alias to the C<zip> function, provided simply to be
695+
explicit about that behaviour as compared to C<zip_shortest>.
693696
694697
=head2 mesh
695698
@@ -700,7 +703,9 @@ I<Since version TODO.>
700703
701704
Returns a list of items collected from elements of the given list of array
702705
references. Each section of items in the returned list is composed of elements
703-
at the corresponding position from each of the given input arrays.
706+
at the corresponding position from each of the given input arrays. If any
707+
input arrays run out of elements before others, then C<undef> will be inserted
708+
into the result to fill in the gaps.
704709
705710
This is similar to L<zip>, except that all of the ranges in the result are
706711
returned in one long flattened list, instead of being bundled into separate
@@ -718,9 +723,10 @@ equivalent to C<List::MoreUtils::mesh> or C<List::MoreUtils::zip> (themselves
718723
aliases of each other). This function does not apply a prototype, so make sure
719724
to invoke it with references to arrays.
720725
721-
my @result = mesh_longest ...
722726
my @result = mesh_shortest ...
723727
728+
my @result = mesh_longest ...
729+
724730
These variations are similar to those of L<zip>, in that they differ in
725731
behaviour when one of the input lists runs out of elements before the others.
726732

0 commit comments

Comments
 (0)