QuantHash Reference
Object hashes with a limitation on the type of values
What it is #
Position in the hierarchy #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
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 Map #
method Map()
Available as of the 2021.02 release of the Rakudo compiler. Coerces the QuantHash object to a Map (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 subclass of QuantHash may have. This is typically Mu, which is also the default for punned QuantHashes.
method Capture #
method Capture()
Returns the object as a Capture by previously coercing it to a Hash.
method list #
multi method list(QuantHash:D:)
Returns a list of Pair objects of all keys and values in the QuantHash.
method Setty #
method Setty(--> Setty:D)
Returns Setty:D.
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.
method Baggy #
method Baggy(--> Baggy:D)
Returns Baggy:D.
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.
method Mixy #
method Mixy(--> Mixy:D)
Returns Mixy:D.
Coerce the QuantHash object to the equivalent object that uses the Mixy role.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
1 no-output · 1 ok · 2 rakupp-differs
role QuantHash does Associative { }Not executed: the documentation states no expected output for this example.
my %b is Bag = one => 1, two => 2; say %b.Setty; # OUTPUT: «Set(one two)» my %m is Mix = one => 1, minus => -1; say %m.Setty; # OUTPUT: «Set(one)»
Set(one two)
Set(one)
Set(one two)
Set(one)
Set(one two)
Set(minus one)
Raku++ disagrees with both the documentation and Rakudo — a defect.
my %s is Set = <one two>; say %s.Baggy; # OUTPUT: «Bag(one two)» my %m is Mix = one => 1, minus => -1; say %m.Baggy; # OUTPUT: «Bag(one)»
Bag(one two)
Bag(one)
Bag(one two)
Bag(one)
Bag(one two)
Bag(minus(-1) one)
Raku++ disagrees with both the documentation and Rakudo — a defect.
my %s is Set = <one two>; say %s.Mixy; # OUTPUT: «Mix(one two)» my %b is Bag = one => 1, two => 2; say %b.Mixy; # OUTPUT: «Mix(one two(2))»
Mix(one two)
Mix(one two(2))
Documentation, Rakudo and Raku++ all agree.