GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Venus::Hash(3) User Contributed Perl Documentation Venus::Hash(3)

Venus::Hash - Hash Class

Hash Class for Perl 5

  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({1..8});
  # $hash->random;

This package provides methods for manipulating hash data.

This package inherits behaviors from:

Venus::Kind::Value

This package integrates behaviors from:

Venus::Role::Mappable

This package provides the following methods:

  all(coderef $code) (boolean)

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

Since 0.01

all example 1
  # given: synopsis;
  my $all = $hash->all(sub {
    $_ > 1
  });
  # 1
    
all example 2
  # given: synopsis;
  my $all = $hash->all(sub {
    my ($key, $value) = @_;
    $value > 1
  });
  # 1
    

  any(coderef $code) (boolean)

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

Since 0.01

any example 1
  # given: synopsis;
  my $any = $hash->any(sub {
    $_ < 1
  });
  # 0
    
any example 2
  # given: synopsis;
  my $any = $hash->any(sub {
    my ($key, $value) = @_;
    $value < 1
  });
  # 0
    

  call(string $iterable, string $method) (any)

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.

Since 1.02

call example 1
  # given: synopsis
  package main;
  my $call = $hash->call('map', 'incr');
  # ['1', 3, '3', 5, '5', 7, '7', 9]
    
call example 2
  # given: synopsis
  package main;
  my $call = $hash->call('grep', 'gt', 4);
  # [5..8]
    

  cast(string $kind) (object | undef)

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.

Since 0.08

cast example 1
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('array');
  # bless({ value => [{}] }, "Venus::Array")
    
cast example 2
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('boolean');
  # bless({ value => 1 }, "Venus::Boolean")
    
cast example 3
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('code');
  # bless({ value => sub { ... } }, "Venus::Code")
    
cast example 4
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('float');
  # bless({ value => "1.0" }, "Venus::Float")
    
cast example 5
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('hash');
  # bless({ value => {} }, "Venus::Hash")
    
cast example 6
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('number');
  # bless({ value => 2 }, "Venus::Number")
    
cast example 7
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('regexp');
  # bless({ value => qr/(?^u:\{\})/ }, "Venus::Regexp")
    
cast example 8
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('scalar');
  # bless({ value => \{} }, "Venus::Scalar")
    
cast example 9
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('string');
  # bless({ value => "{}" }, "Venus::String")
    
cast example 10
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new;
  my $cast = $hash->cast('undef');
  # bless({ value => undef }, "Venus::Undef")
    

  count() (number)

The count method returns the total number of keys defined.

Since 0.01

count example 1
  # given: synopsis;
  my $count = $hash->count;
  # 4
    

  default() (hashref)

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

Since 0.01

default example 1
  # given: synopsis;
  my $default = $hash->default;
  # {}
    

  delete(string $key) (any)

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

Since 0.01

delete example 1
  # given: synopsis;
  my $delete = $hash->delete(1);
  # 2
    

  each(coderef $code) (arrayref)

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.

Since 0.01

each example 1
  # given: synopsis;
  my $each = $hash->each(sub {
    [$_]
  });
  # [[2], [4], [6], [8]]
    
each example 2
  # given: synopsis;
  my $each = $hash->each(sub {
    my ($key, $value) = @_;
    [$key, $value]
  });
  # [[1, 2], [3, 4], [5, 6], [7, 8]]
    

  empty() (hashref)

The empty method drops all elements from the hash.

Since 0.01

empty example 1
  # given: synopsis;
  my $empty = $hash->empty;
  # {}
    

  eq(any $arg) (boolean)

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

Since 0.08

eq example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->eq($rvalue);
  # 1
    
eq example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    
eq example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->eq($rvalue);
  # 0
    

  exists(string $key) (boolean)

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

Since 0.01

exists example 1
  # given: synopsis;
  my $exists = $hash->exists(1);
  # 1
    
exists example 2
  # given: synopsis;
  my $exists = $hash->exists(0);
  # 0
    

  find(string @data) (any)

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.

Since 0.01

find example 1
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $find = $hash->find('foo', 'bar');
  # "baz"
    
find example 2
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $find = $hash->find('bar', 0);
  # "baz"
    
find example 3
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $find = $hash->find('bar');
  # ["baz"]
    
find example 4
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my ($find, $exists) = $hash->find('baz');
  # (undef, 0)
    

  ge(any $arg) (boolean)

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

Since 0.08

ge example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->ge($rvalue);
  # 0
    
ge example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->ge($rvalue);
  # 0
    
ge example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->ge($rvalue);
  # 1
    
ge example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->ge($rvalue);
  # 1
    
ge example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->ge($rvalue);
  # 1
    
ge example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->ge($rvalue);
  # 0
    
ge example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->ge($rvalue);
  # 0
    
ge example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->ge($rvalue);
  # 1
    
ge example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->ge($rvalue);
  # 1
    

  gele(any $arg1, any $arg2) (boolean)

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.

Since 0.08

gele example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    
gele example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->gele($rvalue);
  # 0
    

  grep(coderef $code) (arrayref)

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.

Since 0.01

grep example 1
  # given: synopsis;
  my $grep = $hash->grep(sub {
    $_ >= 3
  });
  # [3..8]
    
grep example 2
  # given: synopsis;
  my $grep = $hash->grep(sub {
    my ($key, $value) = @_;
    $value >= 3
  });
  # [3..8]
    

  gt(any $arg) (boolean)

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

Since 0.08

gt example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->gt($rvalue);
  # 0
    
gt example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->gt($rvalue);
  # 0
    
gt example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->gt($rvalue);
  # 1
    
gt example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->gt($rvalue);
  # 0
    
gt example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->gt($rvalue);
  # 1
    
gt example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->gt($rvalue);
  # 0
    
gt example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->gt($rvalue);
  # 0
    
gt example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->gt($rvalue);
  # 1
    
gt example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->gt($rvalue);
  # 1
    

  gtlt(any $arg1, any $arg2) (boolean)

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

Since 0.08

gtlt example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    
gtlt example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->gtlt($rvalue);
  # 0
    

  iterator() (coderef)

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.

Since 0.01

iterator example 1
  # given: synopsis;
  my $iterator = $hash->iterator;
  # sub { ... }
  # while (my $value = $iterator->()) {
  #   say $value; # 1
  # }
    
iterator example 2
  # given: synopsis;
  my $iterator = $hash->iterator;
  # sub { ... }
  # while (grep defined, my ($key, $value) = $iterator->()) {
  #   say $value; # 1
  # }
    

  keys() (arrayref)

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

Since 0.01

keys example 1
  # given: synopsis;
  my $keys = $hash->keys;
  # [1, 3, 5, 7]
    

  le(any $arg) (boolean)

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

Since 0.08

le example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->le($rvalue);
  # 0
    
le example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->le($rvalue);
  # 1
    
le example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->le($rvalue);
  # 0
    
le example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->le($rvalue);
  # 1
    
le example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->le($rvalue);
  # 0
    
le example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->le($rvalue);
  # 1
    
le example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->le($rvalue);
  # 0
    
le example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->le($rvalue);
  # 0
    
le example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->le($rvalue);
  # 0
    

  length() (number)

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

Since 0.08

length example 1
  # given: synopsis;
  my $length = $hash->length;
  # 4
    

  list() (any)

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

Since 0.01

list example 1
  # given: synopsis;
  my $list = $hash->list;
  # 4
    
list example 2
  # given: synopsis;
  my @list = $hash->list;
  # (1..8)
    

  lt(any $arg) (boolean)

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

Since 0.08

lt example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->lt($rvalue);
  # 1
    
lt example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->lt($rvalue);
  # 1
    
lt example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    
lt example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->lt($rvalue);
  # 0
    

  map(coderef $code) (arrayref)

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.

Since 0.01

map example 1
  # given: synopsis;
  my $map = $hash->map(sub {
    $_ * 2
  });
  # [4, 8, 12, 16]
    
map example 2
  # given: synopsis;
  my $map = $hash->map(sub {
    my ($key, $value) = @_;
    [$key, ($value * 2)]
  });
  # [[1, 4], [3, 8], [5, 12], [7, 16]]
    

  merge(hashref @data) (hashref)

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.

Since 0.01

merge example 1
  # given: synopsis;
  my $merge = $hash->merge({1 => 'a'});
  # { 1 => "a", 3 => 4, 5 => 6, 7 => 8 }
    
merge example 2
  # given: synopsis;
  my $merge = $hash->merge({1 => 'a'}, {5 => 'b'});
  # { 1 => "a", 3 => 4, 5 => "b", 7 => 8 }
    

  ne(any $arg) (boolean)

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

Since 0.08

ne example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->ne($rvalue);
  # 0
    
ne example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    
ne example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->ne($rvalue);
  # 1
    

  none(coderef $code) (boolean)

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

Since 0.01

none example 1
  # given: synopsis;
  my $none = $hash->none(sub {
    $_ < 1
  });
  # 1
    
none example 2
  # given: synopsis;
  my $none = $hash->none(sub {
    my ($key, $value) = @_;
    $value < 1
  });
  # 1
    

  one(coderef $code) (boolean)

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

Since 0.01

one example 1
  # given: synopsis;
  my $one = $hash->one(sub {
    $_ == 2
  });
  # 1
    
one example 2
  # given: synopsis;
  my $one = $hash->one(sub {
    my ($key, $value) = @_;
    $value == 2
  });
  # 1
    

  pairs() (arrayref)

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

Since 0.01

pairs example 1
  # given: synopsis;
  my $pairs = $hash->pairs;
  # [[1, 2], [3, 4], [5, 6], [7, 8]]
    

  path(string $expr) (any)

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.

Since 0.01

path example 1
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $path = $hash->path('/foo/bar');
  # "baz"
    
path example 2
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $path = $hash->path('/bar/0');
  # "baz"
    
path example 3
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my $path = $hash->path('/bar');
  # ["baz"]
    
path example 4
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({'foo' => {'bar' => 'baz'},'bar' => ['baz']});
  my ($path, $exists) = $hash->path('/baz');
  # (undef, 0)
    

  puts(any @args) (arrayref)

The puts method select values from within the underlying data structure using "path" in Venus::Hash, optionally assigning the value to the preceeding scalar reference and returns all the values selected.

Since 3.20

puts example 1
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({
    size => "small",
    fruit => "apple",
    meta => {
      expiry => '5d',
    },
    color => "red",
  });
  my $puts = $hash->puts(undef, 'fruit', undef, 'color');
  # ["apple", "red"]
    
puts example 2
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({
    size => "small",
    fruit => "apple",
    meta => {
      expiry => '5d',
    },
    color => "red",
  });
  $hash->puts(\my $fruit, 'fruit', \my $expiry, 'meta.expiry');
  my $puts = [$fruit, $expiry];
  # ["apple", "5d"]
    
puts example 3
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({
    size => "small",
    fruit => "apple",
    meta => {
      expiry => '5d',
    },
    color => "red",
  });
  $hash->puts(
    \my $fruit, 'fruit',
    \my $color, 'color',
    \my $expiry, 'meta.expiry',
    \my $ripe, 'meta.ripe',
  );
  my $puts = [$fruit, $color, $expiry, $ripe];
  # ["apple", "red", "5d", undef]
    
puts example 4
  package main;
  use Venus::Hash;
  my $hash = Venus::Hash->new({set => [1..20]});
  $hash->puts(
    \my $a, 'set.0',
    \my $b, 'set.1',
    \my $m, ['set', '2:-2'],
    \my $x, 'set.18',
    \my $y, 'set.19',
  );
  my $puts = [$a, $b, $m, $x, $y];
  # [1, 2, [3..18], 19, 20]
    

  random() (any)

The random method returns a random element from the array.

Since 0.01

random example 1
  # given: synopsis;
  my $random = $hash->random;
  # 6
  # my $random = $hash->random;
  # 4
    

  reset() (arrayref)

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

Since 0.01

reset example 1
  # given: synopsis;
  my $reset = $hash->reset;
  # { 1 => undef, 3 => undef, 5 => undef, 7 => undef }
    

  reverse() (hashref)

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

Since 0.01

reverse example 1
  # given: synopsis;
  my $reverse = $hash->reverse;
  # { 2 => 1, 4 => 3, 6 => 5, 8 => 7 }
    

  slice(string @keys) (arrayref)

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

Since 0.01

slice example 1
  # given: synopsis;
  my $slice = $hash->slice(1, 3);
  # [2, 4]
    

  tv(any $arg) (boolean)

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

Since 0.08

tv example 1
  package main;
  use Venus::Array;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Array->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 2
  package main;
  use Venus::Code;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Code->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 3
  package main;
  use Venus::Float;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Float->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 4
  package main;
  use Venus::Hash;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Hash->new;
  my $result = $lvalue->tv($rvalue);
  # 1
    
tv example 5
  package main;
  use Venus::Hash;
  use Venus::Number;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Number->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 6
  package main;
  use Venus::Hash;
  use Venus::Regexp;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Regexp->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 7
  package main;
  use Venus::Hash;
  use Venus::Scalar;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Scalar->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 8
  package main;
  use Venus::Hash;
  use Venus::String;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::String->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    
tv example 9
  package main;
  use Venus::Hash;
  use Venus::Undef;
  my $lvalue = Venus::Hash->new;
  my $rvalue = Venus::Undef->new;
  my $result = $lvalue->tv($rvalue);
  # 0
    

Awncorp, "awncorp@cpan.org"

Copyright (C) 2022, Awncorp, "awncorp@cpan.org".

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.

2023-11-27 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.