callable (constrain) Constraining signatures of Callables

Documentation for callable (constrain) Constraining signatures of Callables assembled from the following types:

class Signature

From Signature

(Signature) callable (constrain) Constraining signatures of Callables

A Callable parameter can be constrained by its signature, by specifying a Signature literal right after the parameter (no whitespace allowed):

sub f(&c:(IntStr))  { say c(10'ten'};
sub g(Int $iStr $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 ~~ :(IntStr))  { say $c(10'ten'}
sub g(Num $iStr $s{ $s ~ $i }
sub h(Int $iStr $s{ $s ~ $i }
# f(&g); # Constraint type check failed 
f(&h);   # OUTPUT: «ten10␤»