In role Associative§

See primary documentation in context for method AT-KEY

method AT-KEY(\key)

Should return the value / container at the given key.

class What { method AT-KEY(\key{ 42 }};
say What.new{33}# OUTPUT: «42␤» 

In Subscripts§

See primary documentation in context for method AT-KEY

multi method AT-KEY (::?CLASS:D: $key)

Expected to return the element associated with $key. This is what postcircumfix { } normally calls.

If you want an element to be mutable (like they are for the built-in Hash type), you'll have to make sure to return it in the form of an item container that evaluates to the element's value when read, and updates it when assigned to. Remember to use return-rw or the is rw routine trait to make that work; see the example.

On the other hand if you want your collection to be read-only, feel free to return non-container values directly.