Skip to content

Commit 9c28c71

Browse files
committed
Add some more examples about what flattens and what does not
1 parent b2e7ebf commit 9c28c71

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/containers.pod

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,25 @@ scalar container) of the invocant, whereas C<.flat> walks the elements of the
293293
invocant, and removes their itemization (note that both methods don't modify
294294
the invocant object; they just return a modified copy).
295295
296+
=item What flattens, what doesn't?
297+
298+
In general, operations that have to iterate the list usually flatten the list.
299+
Other operations don't. Here is a list of a few operations that flattens:
300+
301+
=item .map, .grep, .first
302+
=item Iteration with "for"
303+
=item .join
304+
=item assignment to an array variable
305+
=item assignment to a hash variable
306+
307+
And a few that don't flatten:
308+
309+
=item Indexing with [$idx]
310+
=item .elems
311+
=item .tree
312+
313+
The first two cannot flatten, otherwise it would be very hard to get access
314+
to the structure that's actually stored in the list or parcel, and the whole
315+
point of C<.tree> is not flatten.
316+
296317
=end pod

0 commit comments

Comments
 (0)