Skip to content

Commit

Permalink
Improve Callable signature unpack docs
Browse files Browse the repository at this point in the history
- Get rid of all "reference"s
- Block and Sub doesn't cover all routines; use Callable type instead
- s/argument/parameter/
- Explain whitespace isn't allowed
- Indicate the shorthand only works with `&` sigils and show the long version
    that can be used with other sigils
  • Loading branch information
zoffixznet committed Dec 25, 2017
1 parent b0ec7cb commit ac31bd4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doc/Type/Signature.pod6
Expand Up @@ -276,16 +276,24 @@ The L<Classes and Objects|/language/classtut#Starting_with_class>
document further elaborates on the concepts of instances and type
objects and discovering them with the C<.DEFINITE> method.
=head3 X«Constraining signatures of Callables|function reference (constrain)»
=head3 X«Constraining signatures of Callables|Callable (constrain)»
To constrain L<block|/type/Block> and L<subroutine|/type/Sub> references based
on their signature write the signature after the argument name.
A L<Callable> parameter can be constrained by its signature, by specifying
a L<Signature> literal right after the parameter (no whitespace allowed):
sub f(&c:(Int, Str)) { say c(10, 'ten') };
sub g(Int $i, Str $s) { $s ~ $i };
f(&g);
# OUTPUT: «ten10␤»
This shorthand syntax is available only for parameters with the `&` sigil. For
others, you need to use the long version:
sub f($c: where .signature ~~ :(Int, Str)) { say $c(10, 'ten') };
sub g(Num $i, Str $s) { $s ~ $i };
f(&g);
# OUTPUT: «ten10␤»
=head3 X«Constraining Return Types|-->;returns»
There are multiple ways to constrain return types on a sub or method. All versions below
Expand Down

0 comments on commit ac31bd4

Please sign in to comment.