class RakuAST::Type::Subset { }

The RakuAST::Type::Subset class represents an enum specification.

Object introspection§

RakuAST::Type::Subset object is typically created when parsing Raku Programming Language code. So most developers will only need to know how to introspect the objects created.

is-coercive§

say $subset.is-coercive;  # True or False

The is-coercive method returns whether the "of" type is coercive.

name§

say $subset.name;  # RakuAST::Name.from-identifier("Foo")

Returns the L<RakuAST::Name>|/type/RakuAST/Name object of this RakuAST::Type::Subset object.

of§

say $subset.of;  # RakuAST::Type::Simple.from-identifier("Int")

Returns the RakuAST::Type object of this RakuAST::Type::Subset to which the enum values are constrained.

scope§

say $subset.scope;  # my

Returns the scope of the RakuAST::Type::Subset object as a string. Usually "our", but can also be "my" or "anon".

traits§

dd $subset.traits;  # ()

Returns a (possibly empty) list of RakuAST::Trait object that were applied to the enum.

where§

dd $subset.where;  # * %% 2

Returns the RakuAST::Expression object that represents the names and values of this enum.

Object creation§

There is only one way to create a RakuAST::Type::Subset object.

new§

my $subset = RakuAST::Type::Subset.new(
  scope  => "my",
  name   => RakuAST::Name.from-identifier('Foo'),
  of     => RakuAST::Type::Simple.from-identifier('Int'),
  where  => RakuAST::ApplyInfix.new(
    left  => RakuAST::Term::Whatever.new,
    infix => RakuAST::Infix.new('%%'),
    right => RakuAST::IntLiteral.new(2)
  ),
);
dd $subset;  # my Int subset Foo where * %% 2

Creates a RakuAST::Type::Subset object from the given named arguments.

  • scope - string indicating scope (my/our/anon), default: "our"

  • of - RakuAST::Type object constraining values, default: none

  • name - RakuAST::Name object with the name of the enum, default: ""

  • where - RakuAST::Expression to constrain values with, default: none

  • traits - List of RakuAST::Trait objects, default: none