txt: ## of.md
  of
  
  Combined from primary sources listed below.
  
  # [In Scalar](#___top "go to top of document")[§](#(Scalar)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Scalar#method_of)
  for **method of**.
  
  ```raku
  method of(Scalar:D: --> Mu)
  ```
  
  Returns the type constraint of the container.
  
  Example:
  
  ```raku
  my Cool $x = 42;
  say $x.VAR.of;                  # OUTPUT: «(Cool)␤»
  ```
  
  # [In role Associative](#___top "go to top of document")[§](#(role_Associative)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Associative#method_of)
  for **method of**.
  
  ```raku
  method of()
  ```
  
  `Associative`, as the definition above shows, is actually a [parameterized role](/language/objects#Parameterized_roles) which can use different classes for keys and values. As seen at the top of the document, by default it coerces the key to [`Str`](/type/Str) and uses a very generic [`Mu`](/type/Mu) for value.
  
  ```raku
  my %any-hash;
  say %any-hash.of; # OUTPUT: «(Mu)␤»
  ```
  
  The value is the first parameter you use when instantiating `Associative` with particular classes:
  
  ```raku
  class DateHash is Hash does Associative[Cool,DateTime] {};
  my %date-hash := DateHash.new;
  say %date-hash.of; # OUTPUT: «(Cool)␤»
  ```
  
  # [In Array](#___top "go to top of document")[§](#(Array)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Array#method_of)
  for **method of**.
  
  ```raku
  method of()
  ```
  
  Returns the type constraint for the values of the invocant. By default, i.e. if no type constraint is given during declaration, the method returns `(Mu)`.
  
  ```raku
  my @a1 = 1, 'two', 3.14159;              # (no type constraint specified)
  say @a1.of;                              # OUTPUT: «(Mu)␤»
  
  my Int @a2 = 1, 2, 3;                    # (values must be of type Int)
  say @a2.of;                              # OUTPUT: «(Int)␤»
  @a2.push: 'd';
  CATCH { default { put .^name, ': ', .Str } };
  # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to @a2; expected Int but got Str ("d")␤»
  ```
  
  # [In role Positional](#___top "go to top of document")[§](#(role_Positional)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Positional#method_of)
  for **method of**.
  
  ```raku
  method of()
  ```
  
  Returns the type constraint for elements of the positional container, that is, the `T` in the definition above, which, as it can be seen, defaults to [`Mu`](/type/Mu). It is returned as a type object.
  
  ```raku
  my @þ;
  say @þ.of.^name;   # OUTPUT: «Mu␤
  my Str @þð;
  say @þð.of.raku;   # OUTPUT: «Str␤»
  say (my int @).of; # OUTPUT: «(int)␤»
  
  ```
  
  # [In role QuantHash](#___top "go to top of document")[§](#(role_QuantHash)_method_of "direct link")
  
  See primary documentation
  [in context](/type/QuantHash#method_of)
  for **method of**.
  
  ```raku
  method of()
  ```
  
  Returns the type of value a value of this `QuantHash` may have. This is typically [`Bool`](/type/Bool) for [`Setty`](/type/Setty), [`UInt`](/type/UInt) for [`Baggy`](/type/Baggy) or [`Real`](/type/Real) for [`Mixy`](/type/Mixy) roles.
  
  # [In Variable](#___top "go to top of document")[§](#(Variable)_trait_of "direct link")
  
  See primary documentation
  [in context](/type/Variable#trait_of)
  for **trait of**.
  
  ```raku
  multi trait_mod:<of>(Mu:U $target, Mu:U $type)
  ```
  
  Sets the type constraint of a container bound to a variable.
  
  ```raku
  my $i of Int = 42;
  $i = "forty plus two";
  CATCH { default { say .^name, ' ', .Str } }
  # OUTPUT: «X::TypeCheck::Assignment Type check failed in assignment to $i; expected Int but got Str ("forty plus two")␤»
  ```
  
  You can use any value defined in compile time as a type constraint, including constants:
  
  ```raku
  constant \T = Int;
  my $i of T = 42;
  ```
  
  which would be equivalent to the previous definition.
  
  # [In Code](#___top "go to top of document")[§](#(Code)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Code#method_of)
  for **method of**.
  
  ```raku
  method of(Code:D: --> Mu)
  ```
  
  Returns the [return type constraint](/language/signatures#Constraining_return_types) of the `Code`:
  
  ```raku
  say -> () --> Int {}.of; # OUTPUT: «(Int)␤»
  ```
  
  # [In Hash](#___top "go to top of document")[§](#(Hash)_method_of "direct link")
  
  See primary documentation
  [in context](/type/Hash#method_of)
  for **method of**.
  
  ```raku
  method of(Hash:D:)
  ```
  
  Returns the type constraint for the values of the invocant. By default, i.e., if no type constraint is given during declaration, the method returns `(Mu)`.
  
  ```raku
  my %h1 = 'apples' => 3, 'oranges' => 7;  # (no type constraint specified)
  say %h1.of;                              # OUTPUT: «(Mu)␤»
  
  my Int %h2 = 'oranges' => 7;             # (values must be of type Int)
  say %h2.of;                              # OUTPUT: «(Int)␤»
  ```
  