Skip to content

Commit 2676b46

Browse files
authored
type/Any#duckmap: changing method to routine (#4710)
* changing method to routine for duckmap Part of #4560 * correcting return type for deepmap
1 parent 9520fed commit 2676b46

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

doc/Type/Any.rakudoc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ the L<C<Seq>|/type/Seq> will be iterating over its elements, calling C<.take> on
188188

189189
=head2 routine deepmap
190190

191-
method deepmap(&block --> List) is nodal
192-
multi deepmap(&op, \obj)
191+
method deepmap(&block --> Iterable) is nodal
192+
multi deepmap(&op, \obj --> Iterable)
193193

194194
C<deepmap> will apply its argument (or first argument for the sub form) to
195195
each element and return a new L<C<Iterable>|/type/Iterable> with the return
@@ -210,22 +210,30 @@ In the case of L<C<Associative>|/type/Associative>s, it will be applied to its v
210210
say deepmap *.flip, {what=>'is', this=>'thing', a=><real list>};
211211
# OUTPUT: «{a => (laer tsil), this => gniht, what => si}␤»
212212

213-
=head2 method duckmap
213+
=head2 routine duckmap
214214

215-
method duckmap(&block) is rw is nodal
215+
method duckmap(&block --> Iterable) is rw is nodal
216+
multi duckmap(&op, \obj --> Iterable)
216217

217-
C<duckmap> will apply C<&block> on each element that behaves in such a way that
218-
C<&block> can be applied. If it fails, it will descend recursively if possible,
219-
or otherwise return the item without any transformation. It will act on
220-
values if the object is L<C<Associative>|/type/Associative>.
218+
C<duckmap> will apply its argument (or first argument for the sub form) to each
219+
element that behaves in such a way that the argument can be applied. If it
220+
fails, it will descend recursively if possible, or otherwise return the item
221+
without any transformation. It will act on values if the object is
222+
L<C<Associative>|/type/Associative>.
221223

222224
=for code
223225
<a b c d e f g>.duckmap(-> $_ where <c d e>.any { .uc }).say;
224226
# 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)␤»
225229
(('d', 'e'), 'f').duckmap(-> $_ where <e f>.any { .uc }).say;
226230
# OUTPUT: «((d E) F)␤»
231+
say duckmap -> $_ where <e f>.any { .uc }, (('d', 'e'), 'f');
232+
# OUTPUT: «((d E) F)␤»
227233
{ first => ('d', 'e'), second => 'f'}.duckmap(-> $_ where <e f>.any { .uc }).say;
228234
# 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}␤»
229237

230238
In the first case, it is applied to C<c>, C<d> and C<e> which are the ones that
231239
meet the conditions for the block (C<{ .uc }>) to be applied; the rest are
@@ -236,13 +244,17 @@ so it's visited; that flat list will behave in the same way as the first one. In
236244
this case:
237245

238246
say [[1,2,3],[[4,5],6,7]].duckmap( *² ); # OUTPUT: «[9 9]␤»
247+
say duckmap *², [[1,2,3],[[4,5],6,7]]; # OUTPUT: «[9 9]␤»
248+
239249

240250
You can square anything as long as it behaves like a number. In this case, there
241251
are two arrays with 3 elements each; these arrays will be converted into the
242252
number 3 and squared. In the next case, however
243253

244254
say [[1,2,3],[[4,5],6.1,7.2]].duckmap( -> Rat $_ { $_²} );
245255
# OUTPUT: «[[1 2 3] [[4 5] 37.21 51.84]]␤»
256+
say duckmap -> Rat $_ { $_²}, [[1,2,3],[[4,5],6.1,7.2]];
257+
# OUTPUT: «[[1 2 3] [[4 5] 37.21 51.84]]␤»
246258

247259
3-item lists are not L<C<Rat>|/type/Rat>, so it descends recursively, but eventually only
248260
applies the operation to those that walk (or slither, as the case may be) like a

0 commit comments

Comments
 (0)