Documentation for method type_captures

Documentation for method type_captures, assembled from the following types:

class Parameter

From Parameter

(Parameter) method type_captures

Defined as:

method type_captures(Parameter:D: --> List:D)

Returns a list of variable names of type captures associated with this parameter. Type captures define a type name within the attached code, which is an alias to the type gleaned from the argument during a call.

sub a(::T ::U $x{ T.say }
a(8);                                       # OUTPUT: «(Int)␤» 
say &a.signature.params[0].type_captures;   # OUTPUT: «(T U)␤» 
sub b($x{ $x.^name.say }
a(8);                                       # OUTPUT: «Int␤» 

The type used may change from call to call. Once they are defined, type captures can be used wherever you would use a type, even later in same the signature:

sub c(::T $xT $y$z{ my T $zz = $z };
c(456);          # OK 
c(45"six");      # Fails when assigning to $zz, wants Int not Str 
c("four"5"six"); # Fails when binding $y, wants Str, not Int 

Type captures may be used at the same time as type constraints.

sub d(::T Numeric $xT $y{};
d(45);            # OK 
d(4e05e0);        # OK 
d(4e05);          # Fails when binding $y 
d("four""five");  # Fails when binding $x