NAME ^

src/classes/Mapping.pir - Perl 6 hash class and related functions

Methods ^

hash()

Return invocant as a Hash

perl()

Return perl representation of the invocant.

kv (method)

Returns elements of hash as array of Pair(key, value)

Functions ^

TODO: Functions ^

delete

 our List  multi method Hash::delete ( *@keys )
 our Scalar multi method Hash::delete ( $key ) is default
Deletes the elements specified by $key or $keys from the invocant. returns the value(s) that were associated to those keys.

exists

 our Bool multi method Hash::exists ( $key )
True if invocant has an element whose key matches $key, false otherwise.

keys

kv

pairs

values

 multi Int|List Hash::keys ( %hash : MatchTest *@keytests )
 multi Int|List Hash::kv ( %hash : MatchTest *@keytests )
 multi Int|(List of Pair) Hash::pairs  (%hash : MatchTest *@keytests )
 multi Int|List Hash::values ( %hash : MatchTest *@keytests )
Iterates the elements of %hash in no apparent order, but the order will be the same between successive calls to these functions, as long as %hash doesn't change.

If @keytests are provided, only elements whose keys evaluate $key ~~ any(@keytests) as true are iterated.

What is returned at each element of the iteration varies with function. keys only returns the key; values the value; kv returns both as a 2 element list in (key, value) order, pairs a Pair(key, value).

Note that kv %hash returns the same as zip(keys %hash; values %hash)

In Scalar context, they all return the count of elements that would have been iterated.

The lvalue form of keys is not longer supported. Use the .buckets property instead.


parrot