Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better example per hackedNODE@perl6.party
  • Loading branch information
tbrowder committed Sep 29, 2016
1 parent 5d8221c commit 05c700e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions doc/Type/Signature.pod6
Expand Up @@ -152,9 +152,14 @@ the C<where>-clause inside the sub-signature.
=head3 Constraining Optional Arguments
L<Optional arguments|Optional_and_Mandatory_Parameters> can have constraints, too:
L<Optional arguments|Optional_and_Mandatory_Parameters> can have constraints, too.
Here we want an optional UInt parameter that, if used, must be greater than 5:
sub bin2hex($bin, Int $len where {$len >= 0} = 0) { ... }
sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 } ) { ... }
The signature may be made a bit simpler (but more obscure for the less expert eye) by using defaults:
sub f(Int $a, UInt $i? where { !.defined or $_ > 5 } ) { ... }
=head3 Constraining Slurpy Arguments
Expand Down

0 comments on commit 05c700e

Please sign in to comment.