Skip to content

Commit 7da5ed5

Browse files
committed
Merge pull request #268 from gfldex/master
doc Reduction Operators
2 parents 6e322dc + 06b5c0c commit 7da5ed5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

doc/Language/operators.pod

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,24 @@ C<%outer »+» %inner;> only keys of %inner that exist in %outer will occur in
224224
say %outer «~» %inner; # {"1" => "ax", "2" => "bz"}
225225
226226
=head2 Reduction Operators
227-
TODO
227+
228+
Reduction operators apply any infix operator, surrounded by C<[> and C<]>,
229+
element by element and return the resulting value. They can be defined as a
230+
list prefix operators or will be generated automatically.
231+
232+
say [+] 1,2,3; # 6
233+
234+
For list infix operators, flattening is not done on the input list. This
235+
allowes list operators to become the reduction operator.
236+
237+
[X~] (1,2), <a b> # 1,2 X~ <a b>
238+
239+
By default reduction meta operators are eager. To lazily generate values,
240+
prefix the operater with a C<\>. If the non-meta part contains a C<\> already,
241+
quote it with C<[]> (e.g. C<[\[\x]]>).
242+
243+
my $lazy := [\+] 1..*;
244+
say $lazy[^10]; # (1 3 6 10 15 21 28 36 45 55)
228245
229246
=head2 Cross Operators
230247
TODO

0 commit comments

Comments
 (0)