Skip to content

Commit db05b11

Browse files
committed
Add infix:<∘> to Operators
1 parent 8ae8e7e commit db05b11

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

doc/Language/operators.pod6

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,10 +1164,46 @@ is returned.
11641164
11651165
X<String concatenation operator>.
11661166
1167-
Coerces both arguments to L<Str> and concatenates them. If both arguments are L<Buf>, a combined buffer is returned.
1167+
Coerces both arguments to L<Str> and concatenates them. If both arguments are
1168+
L<Buf|/type/Buf>, a combined buffer is returned.
11681169
11691170
say 'ab' ~ 'c'; # OUTPUT: «abc␤»
11701171
1172+
=head2 infix C«<∘>»
1173+
1174+
multi sub infix:<∘>()
1175+
multi sub infix:<∘>(&f)
1176+
multi sub infix:<∘>(&f, &g --> Block:D)
1177+
1178+
X<Function combinator operator>
1179+
1180+
The function composition operator C«infix:<∘>» or C«infix:<o>» combines two
1181+
functions, so that the left function is called with the return value of the
1182+
right function. If the L«C<.count>|/routine/count» of the left function is
1183+
greater than 1, the return value of the right function will be
1184+
L<slipped|/type/Slip> into the left function.
1185+
1186+
Both C<.count> and C<.arity> of the RHS will be maintained.
1187+
1188+
sub f($p){ say 'f'; $p / 2 }
1189+
sub g($p){ say 'g'; $p * 2 }
1190+
1191+
my &composed = &f ∘ &g;
1192+
say composed 2; # OUTPUT: «g␤f␤2␤»
1193+
# equivalent to:
1194+
say 2.&g.&f;
1195+
# or to:
1196+
say f g 2;
1197+
1198+
=begin code
1199+
sub f($a, $b, $c) { [~] $c, $b, $a }
1200+
sub g($str){ $str.comb }
1201+
my &composed = &f ∘ &g;
1202+
say composed 'abc'; # OUTPUT: «cba␤»
1203+
# equivalent to:
1204+
say f |g 'abc';
1205+
=end code
1206+
11711207
=head1 Junctive AND (all) Precedence
11721208
11731209
=head2 infix C«&»

doc/Type/Callable.pod6

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ including L<Methods|/type/Method> and L<Blocks|/type/Block>:
106106
=head1 Operators
107107
108108
=head2 C«infix:<∘>»
109-
X<|∘,function combinator>X<|o,function combinator>
110109
111110
The function composition operator C«infix:<∘>» or C«infix:<o>» combines two functions, so
112111
that the left function is called with the return value of the right function.

0 commit comments

Comments
 (0)