role QuantHash
Object hashes with a limitation on the type of values
1 | Methods |
1.1 | method hash |
1.2 | method Hash |
1.3 | method of |
1.4 | method keyof |
1.5 | method Setty |
1.6 | method Baggy |
1.7 | method Mixy |
2 | Type Graph |
3 | Routines supplied by role Associative |
3.1 | (Associative) method of |
3.2 | (Associative) method keyof |
3.3 | (Associative) method AT-KEY |
3.4 | (Associative) method EXISTS-KEY |
3.5 | (Associative) method STORE |
does Associative
The QuantHash
role provides the basic functionality shared by the Setty, Baggy and Mixy roles. These provide object hashes whose values are limited in some way.
QuantHashes
are what set operators use internally.
Methods
method hash
method hash()
Coerces the QuantHash
object to a Hash (by stringifying the objects for the keys) with the values of the hash limited to the same limitation as QuantHash
, and returns that.
method Hash
method Hash()
Coerces the QuantHash
object to a Hash (by stringifying the objects for the keys) without any limitations on the values, and returns that.
method of
method of()
Returns the type of value a value of this QuantHash
may have. This is typically Bool for Setty, UInt for Baggy or Real for Mixy roles.
method keyof
method keyof()
Returns the type of value a key of this QuantHash
may have. This is typically Mu.
method Setty
method Setty(--> Setty)
Coerce the QuantHash
object to the equivalent object that uses the Setty role. Note that for Mixy type coercion items with negative values will be skipped.
my is Bag = one => 1, two => 2;say .Setty; # OUTPUT: «set(one two)»my is Mix = one => 1, minus => -1;say .Setty; # OUTPUT: «set(one)»
method Baggy
method Baggy(--> Baggy)
Coerce the QuantHash
object to the equivalent object that uses the Baggy role. Note that for Mixy type coercion items with negative values will be skipped.
my is Set = <one two>;say .Baggy; # OUTPUT: «Bag(one, two)»my is Mix = one => 1, minus => -1;say .Baggy; # OUTPUT: «Bag(one)»
method Mixy
method Mixy(--> Mixy)
Coerce the QuantHash
object to the equivalent object that uses the Mixy role.
my is Set = <one two>;say .Mixy; # OUTPUT: «Mix(one, two)»my is Bag = one => 1, two => 2;say .Mixy; # OUTPUT: «Mix(one, two)»
Type Graph
Routines supplied by role Associative
QuantHash does role Associative, which provides the following routines:
(Associative) method of
Defined as:
method of()
Associative
is actually a parameterized role which can use different classes for keys and values. As seen at the top of the document, 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)»
(Associative) method keyof
Defined as:
method keyof()
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))»
(Associative) method AT-KEY
method AT-KEY(\key)
Should return the value / container at the given key.
(Associative) method EXISTS-KEY
method EXISTS-KEY(\key)
Should return a Bool
indicating whether the given key actually has a value.
(Associative) method STORE
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 Associative
role.
Should accept the values to (re-)initialize the object with, which either could consist of Pair
s, 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.