class RakuAST::Type::Coercion { }
The RakuAST::Type::Coercion class represents a Raku type that coerces.
Object introspection§
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.
base-type§
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.
constraint§
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.
is-coercive§
say $type.is-coercive; # True
The is-coercive method always returns True.
Object creation§
There is only one way to create a RakuAST::Type::Coercion object.
new§
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:
:base-type - RakuAST::Type object for the base type (required)
:constraint - RakuAST::Type object (optional, default: Any)