In Any§

See primary documentation in context for routine nodemap.

method nodemap(&block --> Iterable) is nodal
sub    nodemap(&op, \obj --> Iterable)

nodemap will apply its argument (or first argument for the sub form) to each element and return a new Iterable with the return values of its Callable argument. In contrast to deepmap it will not descend recursively into sublists if it finds elements which do the Iterable role.

say nodemap *+1, [[1,2,3], [[4,5],6,7], 7];
# 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({.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:

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