Collection of objects represented as hash keys
QuantHash represents a set of objects, represented as the keys of a
Hash. When asked to behave as a list it ignores its
.values and returns only
.keys (possibly replicated by weight in the case of bag types). For any
.total methods returns the current sum of the values.
All standard QuantHash containers have a default value that is false (such as
Bool::False), and keep around only those entries with non-default values, automatically deleting any entry if its value goes to that (false) default value.
QuantHash does role Associative, which provides the following routines:
Associative is actually a parameterized role which can use different classes for keys and values. As seen above, by default it coerces to
Str for the key and uses a very generic
Mu for value.
my ;say .of;# OUTPUT: «(Mu)␤»
The value is the first parameter you use when instantiating
Associative with particular classes:
is Hash does Associative[Cool,DateTime] ;my := DateHash.new;say .of; # OUTPUT: «(Cool)␤»
Returns the parameterized key used for the Associative role, which is
Any coerced to
Str by default. This is the class used as second parameter when you use the parameterized version of Associative.
my ;.keyof; #OUTPUT: «(Str(Any))␤»
Should return the value / container at the given key.
Should return a
Bool indicating whether the given key actually has a value.
method STORE(\values, :)
This method should only be supplied if you want to support the:
my is Foo = a => 42, b => 666;
syntax for binding your implementation of the
Should accept the values to (re-)initialize the object with, which either could consist of
Pairs, or separate key/value pairs. The optional named parameter will contain a
True value when the method is called on the object for the first time. Should return the invocant.