Represent a Raku type that coerces
class RakuAST::Type::Coercion { }
The RakuAST::Type::Coercion class represents a Raku type that coerces.
RakuAST::Type::Coercion object is typically created when parsing Raku Programming Language code. So most developers will only need to know how to introspect the objects created.
dd $type.base-type; # Int
The base-type method returns the RakuAST::Type object that was specified with the "base-type" named argument in the call to .new.
dd $type.constraint; # Str
The constraint method returns the RakuAST::Type object that was specified with the "constraint" named argument in the call to .new.
say $type.is-coercive; # True
The is-coercive method always returns True.
There is only one way to create a RakuAST::Type::Coercion object.
my $type = RakuAST::Type::Coercion.new(
base-type => RakuAST::Type::Simple.from-identifier("Int"),
constraint => RakuAST::Type::Simple.from-identifier("Str")
);
dd $type; # Int(Str)
The .new method creates a RakuAST::Type::Coercion object. It expects the following named arguments: