See Original text in context
method AT-KEY(\key)
Should return the value / container at the given key.
;say What.new; # OUTPUT: «42»
See Original text in context
multi method AT-KEY (::?CLASS: )
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.