Skip to content

Commit f1c280c

Browse files
authored
Include example of affecting fold direction in reduce
1 parent 4e48f6a commit f1c280c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

doc/Type/List.pod6

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,13 @@ I<Note:> In the functional programming world, this operation is generally
768768
called a L<fold|
769769
https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29#Folds_on_lists>.
770770
With a right-associative operator it is a right fold, otherwise (and usually)
771-
it is a left fold.
771+
it is a left fold:
772+
773+
sub infix:<foo>($a, $b) is assoc<right> { "($a, $b)" }
774+
say [foo] 1, 2, 3, 4; # OUTPUT: «(1, (2, (3, 4)))␤»
775+
776+
sub infix:<bar>($a, $b) is assoc<left> { "($a, $b)" }
777+
say [bar] 1, 2, 3, 4; # OUTPUT: «(((1, 2), 3), 4)␤»
772778
773779
=head2 routine produce
774780

0 commit comments

Comments
 (0)