@@ -378,8 +378,7 @@ Note that C<map> does not flatten embedded lists and arrays, so
378
378
((1, 2), <a b>).map({ .join(',')})
379
379
380
380
passes C<(1, 2)> and C«<a b>» in turn to the block, leading to a total of
381
- two iterations and the result sequence C<"1,2", "a,b">. See
382
- L<method flatmap|/type/List#method_flatmap> for an alternative that flattens.
381
+ two iterations and the result sequence C<"1,2", "a,b">.
383
382
384
383
If C<&code> is a L<C<Block>|/type/Block> loop phasers will be executed and
385
384
loop control statements will be treated as in loop control flow. Please
@@ -404,26 +403,7 @@ be handled in the context of that L<C<Routine>|/type/Routine>.
404
403
405
404
method flatmap(List:D: &code --> Seq:D)
406
405
407
- Like L«C<map>|/type/Any#routine_map» iterates over the elements of the invocant
408
- list, feeding each element in turn to the code reference, and assembling the
409
- return values from these invocations in a result list.
410
-
411
- The use of C<flatmap> B<is strongly discouraged>. Instead of C<.flatmap( )>,
412
- please use C<.map( ).flat> as it is clear when the C<.flat> is called
413
- and is not confusing like C<.flatmap>.
414
-
415
- Unlike C<map> it flattens non-itemized lists and arrays, so
416
-
417
- ## flatmap
418
- my @list = ('first1', ('second2', ('third3', 'third4'), 'second5'), 'first6');
419
- say @list.flatmap({.reverse}).raku;
420
- # OUTPUT: «("first1", "second5", "third3", "third4", "second2", "first6").Seq»
421
- ## map
422
- say @list.map({"$_ was a {.^name}"}).raku;
423
- # OUTPUT: «("first1 was a Str", "second2 third3 third4 second5 was a List", "first6 was a Str").Seq»
424
- ## .map .flat has the same output as .flatmap
425
- say @list.map({.reverse}).flat.raku;
426
- # OUTPUT: «("first1", "second5", "third3", "third4", "second2", "first6").Seq»
406
+ Convenience method, analogous to L<C<.map(&block)>|#method_map>L<C<.flat>|#method_flat>.
427
407
428
408
=head2 method gist
429
409
0 commit comments