nodemap
ErrorsCollection

nodemap

Synthesised documentation from type/Any

From type/Any

See Original text in context

method nodemap(&block --> Listis 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 [[23], [4, [56]]]».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({.elems == 1 ?? $_ !! slip});
# OUTPUT: «(() () 7)␤» 
say [[2,3], [[4,5],6,7], 7].map({.elems == 1 ?? $_ !! slip});
# OUTPUT: «(7)␤»

When applied to Associatives, it will act on the values:

{ what => "is"this => "thing" }.nodemap*.flip ).say;
# OUTPUT: «{this => gniht, what => si}␤»