role QuantHash 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 subclass of QuantHash may have. This is typically Mu, which is also the default for punned QuantHashes.

method Capture §

Defined as

method Capture()

Returns the object as a Capture by previously coercing it to a Hash.

method list §

Defined as:

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)

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 %b is Bag = one => 1two => 2;
say %b.Setty# OUTPUT: «Set(one two)␤» 
my %m is Mix = one => 1minus => -1;
say %m.Setty# OUTPUT: «Set(one)␤»

method Baggy §

method Baggy(--> 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.

my %s is Set = <one two>;
say %s.Baggy# OUTPUT: «Bag(one two)␤» 
my %m is Mix = one => 1minus => -1;
say %m.Baggy# OUTPUT: «Bag(one)␤»

method Mixy §

method Mixy(--> Mixy:D)

Coerce the QuantHash object to the equivalent object that uses the Mixy role.

my %s is Set = <one two>;
say %s.Mixy# OUTPUT: «Mix(one two)␤» 
my %b is Bag = one => 1two => 2;
say %b.Mixy# OUTPUT: «Mix(one two(2))␤»

Type Graph §

Type relations for QuantHash
perl6-type-graph QuantHash QuantHash Associative Associative QuantHash->Associative Baggy Baggy Baggy->QuantHash Setty Setty Setty->QuantHash Mu Mu Any Any Any->Mu Bag Bag Bag->Baggy Bag->Any BagHash BagHash BagHash->Baggy BagHash->Any Mixy Mixy Mixy->Baggy SetHash SetHash SetHash->Setty SetHash->Any Set Set Set->Setty Set->Any MixHash MixHash MixHash->Any MixHash->Mixy Mix Mix Mix->Any Mix->Mixy

Expand above chart

Routines supplied by role Associative §

QuantHash does role Associative, which provides the following routines:

(Associative) method of §

Defined as:

method of()

Associative, as the definition above shows, 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 the key to Str and uses a very generic Mu for value.

my %any-hash;
say %any-hash.of# OUTPUT: «(Mu)␤»

The value is the first parameter you use when instantiating Associative with particular classes:

class DateHash is Hash does Associative[Cool,DateTime{};
my %date-hash := DateHash.new;
say %date-hash.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 %any-hash;
%any-hash.keyof# OUTPUT: «(Str(Any))␤»

(Associative) 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␤» 

(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:$INITIALIZE)

This method should only be supplied if you want to support the:

my %h is Foo = => 42=> 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 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.

Generated from

Generated from Type/QuantHash.pod6