Skip to content

Commit

Permalink
Junction + first + reflow, refs #2703, #2632
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Apr 3, 2019
1 parent 45ed253 commit db96fe0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions doc/Type/Any.pod6
Expand Up @@ -206,20 +206,28 @@ Defined as:
method duckmap(&block) is rw is nodal
C<duckmap> will apply C<&block> on each element that behaves in such a way that C<&block> can be applied. If it fails, it will descend recursively if possible, or otherwise return the item without any transformation.
C<duckmap> will apply C<&block> on each element that behaves in such a way that
C<&block> can be applied. If it fails, it will descend recursively if possible,
or otherwise return the item without any transformation.
<a b c d e f g>.duckmap(-> $_ where <c d e>.any { .uc }).say;
# OUTPUT: «(a b C D E f g)␤»
(('d', 'e'), 'f').duckmap(-> $_ where <e f>.any { .uc }).say;
# OUTPUT: «((d E) F)␤»
In the first case, it is applied to C<c>, C<d> and C<e> which are the ones that meet the conditions for the block (C<{ .uc }>) to be applied; the rest are returned as is.
In the first case, it is applied to C<c>, C<d> and C<e> which are the ones that
meet the conditions for the block (C<{ .uc }>) to be applied; the rest are
returned as is.
In the second case, the first item is a list that does not meet the condition, so it's visited; that flat list will behave in the same way as the first one. In this case:
In the second case, the first item is a list that does not meet the condition,
so it's visited; that flat list will behave in the same way as the first one. In
this case:
say [[1,2,3],[[4,5],6,7]].duckmap( *² ); # OUTPUT: «[9 9]␤»
You can square anything as long as it behaves like a number. In this case, there are two arrays with 3 elements each; these arrays will be converted into the number 3 and squared. In the next case, however
You can square anything as long as it behaves like a number. In this case, there
are two arrays with 3 elements each; these arrays will be converted into the
number 3 and squared. In the next case, however
say [[1,2,3],[[4,5],6.1,7.2]].duckmap( -> Rat $_ { $_²} );
# OUTPUT: «[[1 2 3] [[4 5] 37.21 51.84]]␤»
Expand Down Expand Up @@ -772,6 +780,10 @@ numbers with two figures, and thus the first that meets that criterion is number
say (⅓,⅔…30).first( * %% 11, :end, :kv ); # OUTPUT: «(65 22)␤»
From version 6.d, the test can also be a C<Junction>:
say (⅓,⅔…30).first( 3 | 33, :kv ); # OUTPUT: «(8 3)␤»
Besides, starts from the C<:end> and returns the C<:kv> in a list; the I<key> in
this case is simply the position it occupies in the C<Seq>.
Expand Down

0 comments on commit db96fe0

Please sign in to comment.