hash
ErrorsCollection

hash

Synthesised documentation from type/Baggy type/Any type/Match type/QuantHash type/Capture

From type/Baggy

See Original text in context

method hash(Baggy:D: --> Hash:D)

Returns a Hash where the elements of the invocant are the keys and their respective weights the values.

my $breakfast = bag <eggs bacon bacon>;
my $h = $breakfast.hash;
say $h.^name;                    # OUTPUT: «Hash[Any,Any]␤» 
say $h;                          # OUTPUT: «{bacon => 2, eggs => 1}␤»

From type/Any

See Original text in context

multi method hash(Any:U:)
multi method hash(Any:D:)

When called on a type object, returns an empty Hash. On instances, it is equivalent to assigning the invocant to a %-sigiled variable and returning that.

Subclasses of Any may choose to return any core type that does the Associative role from .hash. Use .Hash to coerce specifically to Hash.

my $d# $d is Any 
say $d.hash# OUTPUT: {} 
 
my %m is Map = => 42=> 666;
say %m.hash;  # Map.new((a => 42, b => 666)) 
say %m.Hash;  # {a => 42, b => 666} 

From type/Match

See Original text in context

Returns a hash of named submatches.

From type/QuantHash

See Original text in context

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.

From type/Capture

See Original text in context

method hash(Capture:D:)

Returns the named/hash part of the Capture.

my Capture $c = \(235apples => (red => 2));
say $c.hash# OUTPUT: «Map.new((:apples(:red(2))))␤»