Skip to content

Commit 5b29667

Browse files
committed
show how to constrain function references
1 parent fffe595 commit 5b29667

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

doc/Type/Signature.pod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ say limit-lines "a \n b \n c", Int; # "a \n b \n c"
161161
For explicitly indicating the normal behaviour, C<:_> can be used, but this is
162162
unnecessary. C<:(Num:_ $)> is the same as C<:(Num $)>.
163163
164+
=head3 X«Constraining signatures of Callables|function reference (constrain)»
165+
166+
To constrain block and subroutine references based on their signature write
167+
the signature after the argument name.
168+
169+
sub f(&c:(Int, Str)) { say c(10, 'ten') };
170+
sub g(Int $i, Str $s){ $s ~ $i };
171+
f(&g);
172+
# OUTPUT«ten10␤»
173+
164174
=head3 X«Constraining Return Types|-->;returns»
165175
166176
The token C<-->> followed by a type will force a type check on successful

0 commit comments

Comments
 (0)