Venus::Hash

Hash Class

Hash Class for Perl 5

method: all method: any method: call method: cast method: count method: default method: delete method: each method: empty method: eq method: exists method: find method: ge method: gele method: grep method: gt method: gtlt method: iterator method: keys method: le method: length method: list method: lt method: map method: merge method: ne method: none method: one method: pairs method: path method: random method: reset method: reverse method: slice method: tv

package main;

use Venus::Hash;

my $hash = Venus::Hash->new({1..8});

# $hash->random;

This package provides methods for manipulating hash data.

Venus::Kind::Value

Venus::Role::Mappable

The all method returns true if the callback returns true for all of the elements.

all(CodeRef $code) (Bool)

{ since => '0.01', }

=example-1 all

# given: synopsis;

my $all = $hash->all(sub {
  $_ > 1
});

# 1

The any method returns true if the callback returns true for any of the elements.

any(CodeRef $code) (Bool)

{ since => '0.01', }

=example-1 any

# given: synopsis;

my $any = $hash->any(sub {
  $_ < 1
});

# 0

The call method executes the given method (named using the first argument) which performs an iteration (i.e. takes a callback) and calls the method (named using the second argument) on the object (or value) and returns the result of the iterable method.

call(Str $iterable, Str $method) (Any)

{ since => '1.02', }

=example-1 call

# given: synopsis

package main;

my $call = $hash->call('map', 'incr');

# ['1', 3, '3', 5, '5', 7, '7', 9]

The cast method converts "value" objects between different "value" object types, based on the name of the type provided. This method will return undef if the invocant is not a Venus::Kind::Value.

cast(Str $kind) (Object | Undef)

{ since => '0.08', }

=example-1 cast

package main;

use Venus::Hash;

my $hash = Venus::Hash->new;

my $cast = $hash->cast('array');

# bless({ value => [{}] }, "Venus::Array")

The count method returns the total number of keys defined.

count() (Int)

{ since => '0.01', }

=example-1 count

# given: synopsis;

my $count = $hash->count;

# 4

The default method returns the default value, i.e. {}.

default() (HashRef)

{ since => '0.01', }

=example-1 default

# given: synopsis;

my $default = $hash->default;

# {}

The delete method returns the value matching the key specified in the argument and returns the value.

delete(Str $key) (Any)

{ since => '0.01', }

=example-1 delete

# given: synopsis;

my $delete = $hash->delete(1);

# 2

The each method executes callback for each element in the hash passing the routine the key and value at the current position in the loop. This method can return a list of values in list-context.

each(CodeRef $code) (ArrayRef)

{ since => '0.01', }

=example-1 each

# given: synopsis;

my $each = $hash->each(sub {
  [$_]
});

# [[2], [4], [6], [8]]

The empty method drops all elements from the hash.

empty() (HashRef)

{ since => '0.01', }

=example-1 empty

# given: synopsis;

my $empty = $hash->empty;

# {}

The eq method performs an "equals" operation using the argument provided.

eq(Any $arg) (Bool)

{ since => '0.08', }

=example-1 eq

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->eq($rvalue);

# 0

The exists method returns true if the value matching the key specified in the argument exists, otherwise returns false.

exists(Str $key) (Bool)

{ since => '0.01', }

=example-1 exists

# given: synopsis;

my $exists = $hash->exists(1);

# 1

The find method traverses the data structure using the keys and indices provided, returning the value found or undef. In list-context, this method returns a tuple, i.e. the value found and boolean representing whether the match was successful.

find(Str @data) (Any)

{ since => '0.01', }

=example-1 find

package main;

use Venus::Hash;

my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});

my $find = $hash->find('foo', 'bar');

# "baz"

The ge method performs a "greater-than-or-equal-to" operation using the argument provided.

ge(Any $arg) (Bool)

{ since => '0.08', }

=example-1 ge

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->ge($rvalue);

# 0

The gele method performs a "greater-than-or-equal-to" operation on the 1st argument, and "lesser-than-or-equal-to" operation on the 2nd argument.

gele(Any $arg1, Any $arg2) (Bool)

{ since => '0.08', }

=example-1 gele

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->gele($rvalue);

# 0

The grep method executes callback for each key/value pair in the hash passing the routine the key and value at the current position in the loop and returning a new hash reference containing the elements for which the argument evaluated true. This method can return a list of values in list-context.

grep(CodeRef $code) (ArrayRef)

{ since => '0.01', }

=example-1 grep

# given: synopsis;

my $grep = $hash->grep(sub {
  $_ >= 3
});

# [3..8]

The gt method performs a "greater-than" operation using the argument provided.

gt(Any $arg) (Bool)

{ since => '0.08', }

=example-1 gt

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->gt($rvalue);

# 0

The gtlt method performs a "greater-than" operation on the 1st argument, and "lesser-than" operation on the 2nd argument.

gtlt(Any $arg1, Any $arg2) (Bool)

{ since => '0.08', }

=example-1 gtlt

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->gtlt($rvalue);

# 0

The iterator method returns a code reference which can be used to iterate over the hash. Each time the iterator is executed it will return the values of the next element in the hash until all elements have been seen, at which point the iterator will return an undefined value. This method can return a tuple with the key and value in list-context.

iterator() (CodeRef)

{ since => '0.01', }

=example-1 iterator

# given: synopsis;

my $iterator = $hash->iterator;

# sub { ... }

# while (my $value = $iterator->()) {
#   say $value; # 1
# }

The keys method returns an array reference consisting of all the keys in the hash.

keys() (ArrayRef)

{ since => '0.01', }

=example-1 keys

# given: synopsis;

my $keys = $hash->keys;

# [1, 3, 5, 7]

The le method performs a "lesser-than-or-equal-to" operation using the argument provided.

le(Any $arg) (Bool)

{ since => '0.08', }

=example-1 le

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->le($rvalue);

# 0

The length method returns the total number of keys defined, and is an alias for the "count" method.

length() (Int)

{ since => '0.08', }

=example-1 length

# given: synopsis;

my $length = $hash->length;

# 4

The list method returns a shallow copy of the underlying hash reference as an array reference.

list() (Any)

{ since => '0.01', }

=example-1 list

# given: synopsis;

my $list = $hash->list;

# 4

The lt method performs a "lesser-than" operation using the argument provided.

lt(Any $arg) (Bool)

{ since => '0.08', }

=example-1 lt

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->lt($rvalue);

# 0

The map method executes callback for each key/value in the hash passing the routine the value at the current position in the loop and returning a new hash reference containing the elements for which the argument returns a value or non-empty list. This method can return a list of values in list-context.

map(CodeRef $code) (ArrayRef)

{ since => '0.01', }

=example-1 map

# given: synopsis;

my $map = $hash->map(sub {
  $_ * 2
});

# [4, 8, 12, 16]

The merge method returns a hash reference where the elements in the hash and the elements in the argument(s) are merged. This operation performs a deep merge and clones the datasets to ensure no side-effects. The merge behavior merges hash references only, all other data types are assigned with precendence given to the value being merged.

merge(HashRef @data) (HashRef)

{ since => '0.01', }

=example-1 merge

# given: synopsis;

my $merge = $hash->merge({1 => 'a'});

# { 1 => "a", 3 => 4, 5 => 6, 7 => 8 }

The ne method performs a "not-equal-to" operation using the argument provided.

ne(Any $arg) (Bool)

{ since => '0.08', }

=example-1 ne

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->ne($rvalue);

# 1

The none method returns true if none of the elements in the array meet the criteria set by the operand and rvalue.

none(CodeRef $code) (Bool)

{ since => '0.01', }

=example-1 none

# given: synopsis;

my $none = $hash->none(sub {
  $_ < 1
});

# 1

The one method returns true if only one of the elements in the array meet the criteria set by the operand and rvalue.

one(CodeRef $code) (Bool)

{ since => '0.01', }

=example-1 one

# given: synopsis;

my $one = $hash->one(sub {
  $_ == 2
});

# 1

The pairs method is an alias to the pairs_array method. This method can return a list of values in list-context.

pairs() (ArrayRef)

{ since => '0.01', }

=example-1 pairs

# given: synopsis;

my $pairs = $hash->pairs;

# [[1, 2], [3, 4], [5, 6], [7, 8]]

The path method traverses the data structure using the path expr provided, returning the value found or undef. In list-context, this method returns a tuple, i.e. the value found and boolean representing whether the match was successful.

path(Str $expr) (Any)

{ since => '0.01', }

=example-1 path

package main;

use Venus::Hash;

my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});

my $path = $hash->path('/foo/bar');

# "baz"

The random method returns a random element from the array.

random() (Any)

{ since => '0.01', }

=example-1 random

# given: synopsis;

my $random = $hash->random;

# 6

# my $random = $hash->random;

# 4

The reset method returns nullifies the value of each element in the hash.

reset() (ArrayRef)

{ since => '0.01', }

=example-1 reset

# given: synopsis;

my $reset = $hash->reset;

# { 1 => undef, 3 => undef, 5 => undef, 7 => undef }

The reverse method returns a hash reference consisting of the hash's keys and values inverted. Note, keys with undefined values will be dropped.

reverse() (HashRef)

{ since => '0.01', }

=example-1 reverse

# given: synopsis;

my $reverse = $hash->reverse;

# { 2 => 1, 4 => 3, 6 => 5, 8 => 7 }

The slice method returns an array reference of the values that correspond to the key(s) specified in the arguments.

slice(Str @keys) (ArrayRef)

{ since => '0.01', }

=example-1 slice

# given: synopsis;

my $slice = $hash->slice(1, 3);

# [2, 4]

The tv method performs a "type-and-value-equal-to" operation using argument provided.

tv(Any $arg) (Bool)

{ since => '0.08', }

=example-1 tv

package main;

use Venus::Array;
use Venus::Hash;

my $lvalue = Venus::Hash->new;
my $rvalue = Venus::Array->new;

my $result = $lvalue->tv($rvalue);

# 0

t/Venus.t: pdml: authors t/Venus.t: pdml: license

213 POD Errors

The following errors were encountered while parsing the POD:

Around line 13:

Unknown directive: =name

Around line 21:

Unknown directive: =tagline

Around line 29:

Unknown directive: =abstract

Around line 37:

Unknown directive: =includes

Around line 79:

Unknown directive: =synopsis

Around line 99:

Unknown directive: =description

Around line 107:

Unknown directive: =inherits

Around line 115:

Unknown directive: =integrates

Around line 123:

Unknown directive: =method

Around line 128:

Unknown directive: =signature

Around line 132:

Unknown directive: =metadata

Around line 170:

=cut found outside a pod block. Skipping to next block.

Around line 180:

Unknown directive: =method

Around line 185:

Unknown directive: =signature

Around line 189:

Unknown directive: =metadata

Around line 227:

=cut found outside a pod block. Skipping to next block.

Around line 237:

Unknown directive: =method

Around line 244:

Unknown directive: =signature

Around line 248:

Unknown directive: =metadata

Around line 284:

=cut found outside a pod block. Skipping to next block.

Around line 294:

Unknown directive: =method

Around line 300:

Unknown directive: =signature

Around line 304:

Unknown directive: =metadata

Around line 346:

=cut found outside a pod block. Skipping to next block.

Around line 370:

=cut found outside a pod block. Skipping to next block.

Around line 394:

=cut found outside a pod block. Skipping to next block.

Around line 418:

=cut found outside a pod block. Skipping to next block.

Around line 442:

=cut found outside a pod block. Skipping to next block.

Around line 466:

=cut found outside a pod block. Skipping to next block.

Around line 490:

=cut found outside a pod block. Skipping to next block.

Around line 514:

=cut found outside a pod block. Skipping to next block.

Around line 538:

=cut found outside a pod block. Skipping to next block.

Around line 550:

Unknown directive: =method

Around line 554:

Unknown directive: =signature

Around line 558:

Unknown directive: =metadata

Around line 582:

Unknown directive: =method

Around line 586:

Unknown directive: =signature

Around line 590:

Unknown directive: =metadata

Around line 614:

Unknown directive: =method

Around line 619:

Unknown directive: =signature

Around line 623:

Unknown directive: =metadata

Around line 647:

Unknown directive: =method

Around line 653:

Unknown directive: =signature

Around line 657:

Unknown directive: =metadata

Around line 695:

=cut found outside a pod block. Skipping to next block.

Around line 705:

Unknown directive: =method

Around line 709:

Unknown directive: =signature

Around line 713:

Unknown directive: =metadata

Around line 737:

Unknown directive: =method

Around line 741:

Unknown directive: =signature

Around line 745:

Unknown directive: =metadata

Around line 789:

=cut found outside a pod block. Skipping to next block.

Around line 813:

=cut found outside a pod block. Skipping to next block.

Around line 836:

=cut found outside a pod block. Skipping to next block.

Around line 860:

=cut found outside a pod block. Skipping to next block.

Around line 884:

=cut found outside a pod block. Skipping to next block.

Around line 908:

=cut found outside a pod block. Skipping to next block.

Around line 932:

=cut found outside a pod block. Skipping to next block.

Around line 956:

=cut found outside a pod block. Skipping to next block.

Around line 966:

Unknown directive: =method

Around line 971:

Unknown directive: =signature

Around line 975:

Unknown directive: =metadata

Around line 1007:

=cut found outside a pod block. Skipping to next block.

Around line 1017:

Unknown directive: =method

Around line 1024:

Unknown directive: =signature

Around line 1028:

Unknown directive: =metadata

Around line 1068:

=cut found outside a pod block. Skipping to next block.

Around line 1090:

=cut found outside a pod block. Skipping to next block.

Around line 1112:

=cut found outside a pod block. Skipping to next block.

Around line 1124:

Unknown directive: =method

Around line 1129:

Unknown directive: =signature

Around line 1133:

Unknown directive: =metadata

Around line 1177:

=cut found outside a pod block. Skipping to next block.

Around line 1201:

=cut found outside a pod block. Skipping to next block.

Around line 1224:

=cut found outside a pod block. Skipping to next block.

Around line 1248:

=cut found outside a pod block. Skipping to next block.

Around line 1272:

=cut found outside a pod block. Skipping to next block.

Around line 1296:

=cut found outside a pod block. Skipping to next block.

Around line 1320:

=cut found outside a pod block. Skipping to next block.

Around line 1344:

=cut found outside a pod block. Skipping to next block.

Around line 1354:

Unknown directive: =method

Around line 1359:

Unknown directive: =signature

Around line 1363:

Unknown directive: =metadata

Around line 1407:

=cut found outside a pod block. Skipping to next block.

Around line 1431:

=cut found outside a pod block. Skipping to next block.

Around line 1454:

=cut found outside a pod block. Skipping to next block.

Around line 1478:

=cut found outside a pod block. Skipping to next block.

Around line 1502:

=cut found outside a pod block. Skipping to next block.

Around line 1526:

=cut found outside a pod block. Skipping to next block.

Around line 1550:

=cut found outside a pod block. Skipping to next block.

Around line 1574:

=cut found outside a pod block. Skipping to next block.

Around line 1584:

Unknown directive: =method

Around line 1591:

Unknown directive: =signature

Around line 1595:

Unknown directive: =metadata

Around line 1633:

=cut found outside a pod block. Skipping to next block.

Around line 1643:

Unknown directive: =method

Around line 1647:

Unknown directive: =signature

Around line 1651:

Unknown directive: =metadata

Around line 1695:

=cut found outside a pod block. Skipping to next block.

Around line 1719:

=cut found outside a pod block. Skipping to next block.

Around line 1742:

=cut found outside a pod block. Skipping to next block.

Around line 1766:

=cut found outside a pod block. Skipping to next block.

Around line 1790:

=cut found outside a pod block. Skipping to next block.

Around line 1814:

=cut found outside a pod block. Skipping to next block.

Around line 1838:

=cut found outside a pod block. Skipping to next block.

Around line 1862:

=cut found outside a pod block. Skipping to next block.

Around line 1872:

Unknown directive: =method

Around line 1877:

Unknown directive: =signature

Around line 1881:

Unknown directive: =metadata

Around line 1925:

=cut found outside a pod block. Skipping to next block.

Around line 1949:

=cut found outside a pod block. Skipping to next block.

Around line 1972:

=cut found outside a pod block. Skipping to next block.

Around line 1996:

=cut found outside a pod block. Skipping to next block.

Around line 2020:

=cut found outside a pod block. Skipping to next block.

Around line 2044:

=cut found outside a pod block. Skipping to next block.

Around line 2068:

=cut found outside a pod block. Skipping to next block.

Around line 2092:

=cut found outside a pod block. Skipping to next block.

Around line 2102:

Unknown directive: =method

Around line 2110:

Unknown directive: =signature

Around line 2114:

Unknown directive: =metadata

Around line 2156:

=cut found outside a pod block. Skipping to next block.

Around line 2169:

Unknown directive: =method

Around line 2174:

Unknown directive: =signature

Around line 2178:

Unknown directive: =metadata

Around line 2202:

Unknown directive: =method

Around line 2207:

Unknown directive: =signature

Around line 2211:

Unknown directive: =metadata

Around line 2255:

=cut found outside a pod block. Skipping to next block.

Around line 2279:

=cut found outside a pod block. Skipping to next block.

Around line 2302:

=cut found outside a pod block. Skipping to next block.

Around line 2326:

=cut found outside a pod block. Skipping to next block.

Around line 2350:

=cut found outside a pod block. Skipping to next block.

Around line 2374:

=cut found outside a pod block. Skipping to next block.

Around line 2398:

=cut found outside a pod block. Skipping to next block.

Around line 2422:

=cut found outside a pod block. Skipping to next block.

Around line 2432:

Unknown directive: =method

Around line 2437:

Unknown directive: =signature

Around line 2441:

Unknown directive: =metadata

Around line 2465:

Unknown directive: =method

Around line 2470:

Unknown directive: =signature

Around line 2474:

Unknown directive: =metadata

Around line 2506:

=cut found outside a pod block. Skipping to next block.

Around line 2516:

Unknown directive: =method

Around line 2520:

Unknown directive: =signature

Around line 2524:

Unknown directive: =metadata

Around line 2568:

=cut found outside a pod block. Skipping to next block.

Around line 2592:

=cut found outside a pod block. Skipping to next block.

Around line 2615:

=cut found outside a pod block. Skipping to next block.

Around line 2639:

=cut found outside a pod block. Skipping to next block.

Around line 2663:

=cut found outside a pod block. Skipping to next block.

Around line 2687:

=cut found outside a pod block. Skipping to next block.

Around line 2711:

=cut found outside a pod block. Skipping to next block.

Around line 2735:

=cut found outside a pod block. Skipping to next block.

Around line 2745:

Unknown directive: =method

Around line 2752:

Unknown directive: =signature

Around line 2756:

Unknown directive: =metadata

Around line 2794:

=cut found outside a pod block. Skipping to next block.

Around line 2804:

Unknown directive: =method

Around line 2812:

Unknown directive: =signature

Around line 2816:

Unknown directive: =metadata

Around line 2848:

=cut found outside a pod block. Skipping to next block.

Around line 2858:

Unknown directive: =method

Around line 2862:

Unknown directive: =signature

Around line 2866:

Unknown directive: =metadata

Around line 2910:

=cut found outside a pod block. Skipping to next block.

Around line 2934:

=cut found outside a pod block. Skipping to next block.

Around line 2957:

=cut found outside a pod block. Skipping to next block.

Around line 2981:

=cut found outside a pod block. Skipping to next block.

Around line 3005:

=cut found outside a pod block. Skipping to next block.

Around line 3029:

=cut found outside a pod block. Skipping to next block.

Around line 3053:

=cut found outside a pod block. Skipping to next block.

Around line 3077:

=cut found outside a pod block. Skipping to next block.

Around line 3087:

Unknown directive: =method

Around line 3092:

Unknown directive: =signature

Around line 3096:

Unknown directive: =metadata

Around line 3134:

=cut found outside a pod block. Skipping to next block.

Around line 3144:

Unknown directive: =method

Around line 3149:

Unknown directive: =signature

Around line 3153:

Unknown directive: =metadata

Around line 3191:

=cut found outside a pod block. Skipping to next block.

Around line 3201:

Unknown directive: =method

Around line 3206:

Unknown directive: =signature

Around line 3210:

Unknown directive: =metadata

Around line 3234:

Unknown directive: =method

Around line 3241:

Unknown directive: =signature

Around line 3245:

Unknown directive: =metadata

Around line 3285:

=cut found outside a pod block. Skipping to next block.

Around line 3307:

=cut found outside a pod block. Skipping to next block.

Around line 3329:

=cut found outside a pod block. Skipping to next block.

Around line 3341:

Unknown directive: =method

Around line 3345:

Unknown directive: =signature

Around line 3349:

Unknown directive: =metadata

Around line 3376:

Unknown directive: =method

Around line 3380:

Unknown directive: =signature

Around line 3384:

Unknown directive: =metadata

Around line 3408:

Unknown directive: =method

Around line 3413:

Unknown directive: =signature

Around line 3417:

Unknown directive: =metadata

Around line 3441:

Unknown directive: =method

Around line 3446:

Unknown directive: =signature

Around line 3450:

Unknown directive: =metadata

Around line 3474:

Unknown directive: =method

Around line 3479:

Unknown directive: =signature

Around line 3483:

Unknown directive: =metadata

Around line 3527:

=cut found outside a pod block. Skipping to next block.

Around line 3551:

=cut found outside a pod block. Skipping to next block.

Around line 3574:

=cut found outside a pod block. Skipping to next block.

Around line 3598:

=cut found outside a pod block. Skipping to next block.

Around line 3622:

=cut found outside a pod block. Skipping to next block.

Around line 3646:

=cut found outside a pod block. Skipping to next block.

Around line 3670:

=cut found outside a pod block. Skipping to next block.

Around line 3694:

=cut found outside a pod block. Skipping to next block.

Around line 3704:

Unknown directive: =partials