Last active
June 17, 2017 19:04
-
-
Save dogbert17/bdc044f30b5cf3e387e07cdd84ab2694 to your computer and use it in GitHub Desktop.
Attempt to document nodemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=head2 method nodemap | |
Defined as: | |
method nodemap(&block --> List) is nodal | |
C<nodemap> will apply C<&block> to each element and return a new C<List> with | |
the return values of C<&block>. In contrast to C<deepmap> it will B<not> descend | |
recursively into sublists if it finds elements which does the C<Iterable> role. | |
say [[1,2,3], [[4,5],6,7], 7].nodemap(*+1); | |
# OUTPUT: «(4, 4, 8)» | |
say [[2, 3], [4, [5, 6]]]».nodemap(*+1) | |
# OUTPUT: «((3 4) (5 3))» | |
The examples above would have produced the exact same results if we had used | |
C<map> instead of C<nodemap>. The difference between the two lies in the | |
fact that C<map> can handle L<slips|/type/Slip> something which C<nodemap> | |
can't. | |
say [[2,3], [[4,5],6,7], 7].nodemap({.elems == 1 ?? $_ !! slip}); | |
# OUTPUT: «(() () 7)» | |
say [[2,3], [[4,5],6,7], 7].map({.elems == 1 ?? $_ !! slip}); | |
# OUTPUT: «(7)» |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment