method hash

Documentation for method hash assembled from the following types:

class Any

From Any

(Any) method hash

Defined as:

proto method hash(|) is nodal
multi method hash(Any:U: --> Hash:D)
multi method hash(Any:D: --> Hash:D)

Coerces a type object to an empty Hash.

More generally, coerces a defined invocant to something that supports the Associative role. This may be a mutable Hash, but may also be an immutable Map or anything else that supports the Associative role. Use the .Hash method if you really want to have a mutable Hash, or the .Map coercer if you're happy enough with an immutable Map. Use the .hash coercer if you really don't care and want the cheapest way to get an object that does the Associative role.

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} 

role Baggy

From Baggy

(Baggy) method hash

Defined as:

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}␤» 

class Capture

From Capture

(Capture) method hash

Defined as:

method hash(Capture:D: --> Associative)

Returns the named/hash part of the Capture.

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

class Match

From Match

(Match) method hash

Returns a hash of named submatches.