NAME ^

src/classes/CardinalHash.pir - Cardinal hash class and related functions

Methods ^

to_s (method)

Returns a string of keys and values appended together.

kv (method)

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

each(block)

Run block once for each item in self, with the key and value passed as args.

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