@@ -189,7 +189,7 @@ the L<C<Seq>|/type/Seq> will be iterating over its elements, calling C<.take> on
189189=head2 routine deepmap
190190
191191 method deepmap(&block --> Iterable) is nodal
192- multi deepmap(&op, \obj --> Iterable)
192+ sub deepmap(&op, \obj --> Iterable)
193193
194194C<deepmap> will apply its argument (or first argument for the sub form) to
195195each element and return a new L<C<Iterable>|/type/Iterable> with the return
@@ -213,7 +213,7 @@ say deepmap *.flip, {what=>'is', this=>'thing', a=><real list>};
213213=head2 routine duckmap
214214
215215 method duckmap(&block --> Iterable) is rw is nodal
216- multi duckmap(&op, \obj --> Iterable)
216+ sub duckmap(&op, \obj --> Iterable)
217217
218218C<duckmap> will apply its argument (or first argument for the sub form) to each
219219element that behaves in such a way that the argument can be applied. If it
@@ -224,57 +224,49 @@ L<C<Associative>|/type/Associative>.
224224=for code
225225<a b c d e f g>.duckmap(-> $_ where <c d e>.any { .uc }).say;
226226# OUTPUT: «(a b C D E f g)»
227- say duckmap -> $_ where <c d e>.any { .uc }, <a b c d e f g>;
228- # OUTPUT: «(a b C D E f g)»
229227(('d', 'e'), 'f').duckmap(-> $_ where <e f>.any { .uc }).say;
230228# OUTPUT: «((d E) F)»
231- say duckmap -> $_ where <e f>.any { .uc }, (('d', 'e'), 'f');
232- # OUTPUT: «((d E) F)»
233229{ first => ('d', 'e'), second => 'f'}.duckmap(-> $_ where <e f>.any { .uc }).say;
234230# OUTPUT: «{first => (d E), second => F}»
235- say duckmap -> $_ where <e f>.any { .uc }, { first => ('d', 'e'), second => 'f'};
236- # OUTPUT: «{first => (d E), second => F}»
237231
238232In the first case, it is applied to C<c>, C<d> and C<e> which are the ones that
239233meet the conditions for the block (C<{ .uc }>) to be applied; the rest are
240234returned as is.
241235
242236In the second case, the first item is a list that does not meet the condition,
243- so it's visited; that flat list will behave in the same way as the first one. In
244- this case:
237+ so it's visited; that flat list will behave in the same way as the first one.
238+ Similarly in the third case; here it's only the values in each pair that are
239+ visited.
245240
246- say [[1,2,3],[[4,5],6,7]].duckmap( *² ); # OUTPUT: «[9 9]»
247241 say duckmap *², [[1,2,3],[[4,5],6,7]]; # OUTPUT: «[9 9]»
248242
249-
250243You can square anything as long as it behaves like a number. In this case, there
251244are two arrays with 3 elements each; these arrays will be converted into the
252245number 3 and squared. In the next case, however
253246
254- say [[1,2,3],[[4,5],6.1,7.2]].duckmap( -> Rat $_ { $_²} );
255- # OUTPUT: «[[1 2 3] [[4 5] 37.21 51.84]]»
256247 say duckmap -> Rat $_ { $_²}, [[1,2,3],[[4,5],6.1,7.2]];
257248 # OUTPUT: «[[1 2 3] [[4 5] 37.21 51.84]]»
258249
2592503-item lists are not L<C<Rat>|/type/Rat>, so it descends recursively, but eventually only
260- applies the operation to those that walk (or slither, as the case may be) like a
261- L<C<Rat>|/type/Rat>.
251+ applies the operation to those that match L<C<Rat>|/type/Rat>.
262252
263253Although on the surface (and name), C<duckmap> might look similar to
264254L<C<deepmap>|/routine/deepmap>, the latter is applied recursively regardless of
265255the type of the item.
266256
267- =head2 method nodemap
257+ =head2 routine nodemap
268258
269- method nodemap(&block --> List) is nodal
259+ method nodemap(&block --> Iterable) is nodal
260+ sub nodemap(&op, \obj --> Iterable)
270261
271- C<nodemap> will apply C<&block> to each element and return a new
272- L<C<List>|/type/List> with the return values of C<&block>. In contrast to
262+ C<nodemap> will apply its argument (or first argument for the sub form) to each
263+ element and return a new L<C<Iterable>|/type/Iterable> with the return values
264+ of its L<C<Callable>|/type/Callable> argument. In contrast to
273265L<deepmap|/routine/deepmap> it will B<not> descend recursively into sublists if
274266it finds elements which L<do|/routine/does> the L<C<Iterable>|/type/Iterable>
275267role.
276268
277- say [[1,2,3], [[4,5],6,7], 7].nodemap(*+1) ;
269+ say nodemap *+1, [[1,2,3], [[4,5],6,7], 7];
278270 # OUTPUT: «(4, 4, 8)»
279271
280272 say [[2, 3], [4, [5, 6]]]».nodemap(*+1)
@@ -292,7 +284,7 @@ C<nodemap> doesn't.
292284
293285When applied to L<C<Associative>|/type/Associative>s, it will act on the values:
294286
295- { what => "is", this => "thing" }.nodemap( *.flip ).say ;
287+ say nodemap *.flip, { what => "is", this => "thing" };
296288 # OUTPUT: «{this => gniht, what => si}»
297289
298290=head2 method flat
0 commit comments