coercion type (signature) Coercion Type

Documentation for coercion type (signature) Coercion Type, assembled from the following types:

class Signature

From Signature

(Signature) coercion type (signature) Coercion Type

To accept one type but coerce it automatically to another, use the accepted type as an argument to the target type. If the accepted type is Any it can be omitted.

sub f(Int(Str$want-intStr() $want-str{
    say $want-int.^name ~ ' ' ~ $want-str.^name
f '10'10;
# OUTPUT: «Int Str␤» 
augment class Str { method Date() {} };
sub foo(Date(Str$d{ say $d.^namesay $d };
foo "2016-12-01";
# OUTPUT: «Date␤2016-12-01␤»