See Original text in context
method nodemap( --> List) is nodal
nodemap
will apply &block
to each element and return a new Any with the return values of &block
. In contrast to deepmap it will not descend recursively into sublists if it finds elements which do the 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 map instead of nodemap
. The difference between the two lies in the fact that map flattens out slips while nodemap
doesn't.
say [[2,3], [[4,5],6,7], 7].nodemap();# OUTPUT: «(() () 7)»say [[2,3], [[4,5],6,7], 7].map();# OUTPUT: «(7)»
When applied to Associative
s, it will act on the values:
.nodemap( *.flip ).say;# OUTPUT: «{this => gniht, what => si}»