Skip to content

Commit c84bbed

Browse files
committed
tell that where clauses are executed on not provided optional arguments
1 parent a6c627c commit c84bbed

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

doc/Type/Signature.pod6

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,13 @@ the C<where>-clause inside the sub-signature.
152152
153153
=head3 Constraining Optional Arguments
154154
155-
L<Optional arguments|Optional_and_Mandatory_Parameters> can have constraints, too.
156-
Here we want an optional UInt parameter that, if used, must be greater than 5:
155+
L<Optional arguments|Optional_and_Mandatory_Parameters> can have constraints,
156+
too. Any C<where> clause on any parameter will be executed, even if it's
157+
optional and not provided by the caller. In that case you may have to guard
158+
against undefined values whitin the C<where> clause.
157159
158160
sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 } ) { ... }
159161
160-
The signature may be made a bit simpler (but more obscure for the less expert eye) by using defaults:
161-
162-
sub f(Int $a, UInt $i? where { !.defined or $_ > 5 } ) { ... }
163-
164162
=head3 Constraining Slurpy Arguments
165163
166164
L<Slurpy arguments|Slurpy_(A.K.A._Variadic)_Parameters> can not have type

0 commit comments

Comments
 (0)