NAME
Venus::Array - Array Class
ABSTRACT
Array Class for Perl 5
SYNOPSIS
package main;
use Venus::Array;
my $array = Venus::Array->new([1..9]);
# $array->random;
DESCRIPTION
This package provides methods for manipulating array data.
INHERITS
This package inherits behaviors from:
INTEGRATES
This package integrates behaviors from:
METHODS
This package provides the following methods:
all
all(CodeRef $code) (Bool)
The all method returns true if the callback returns true for all of the elements.
Since 0.01
- all example 2
-
# given: synopsis; my $all = $array->all(sub { my ($key, $value) = @_; $value > 0; }); # 1
any
any(CodeRef $code) (Bool)
The any method returns true if the callback returns true for any of the elements.
Since 0.01
- any example 2
-
# given: synopsis; my $any = $array->any(sub { my ($key, $value) = @_; $value > 4; });
call
call(Str $iterable, Str $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
cast
cast(Str $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::Array; my $array = Venus::Array->new; my $cast = $array->cast('array'); # bless({ value => [] }, "Venus::Array")
- cast example 2
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('boolean'); # bless({ value => 1 }, "Venus::Boolean")
- cast example 3
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('code'); # bless({ value => sub { ... } }, "Venus::Code")
- cast example 4
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('float'); # bless({ value => "1.0" }, "Venus::Float")
- cast example 5
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('hash'); # bless({ value => {} }, "Venus::Hash")
- cast example 6
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('number'); # bless({ value => 2 }, "Venus::Number")
- cast example 7
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('regexp'); # bless({ value => qr/(?^u:\[\])/ }, "Venus::Regexp")
- cast example 8
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('scalar'); # bless({ value => \[] }, "Venus::Scalar")
- cast example 9
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('string'); # bless({ value => "[]" }, "Venus::String")
- cast example 10
-
package main; use Venus::Array; my $array = Venus::Array->new; my $cast = $array->cast('undef'); # bless({ value => undef }, "Venus::Undef")
count
count() (Int)
The count method returns the number of elements within the array.
Since 0.01
default
default() (ArrayRef)
The default method returns the default value, i.e. []
.
Since 0.01
delete
delete(Int $index) (Any)
The delete method returns the value of the element at the index specified after removing it from the array.
Since 0.01
each
each(CodeRef $code) (ArrayRef)
The each method executes a callback for each element in the array passing the index and value as arguments. This method can return a list of values in list-context.
Since 0.01
- each example 1
-
# given: synopsis; my $each = $array->each(sub { [$_] }); # [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
- each example 2
-
# given: synopsis; my $each = $array->each(sub { my ($key, $value) = @_; [$key, $value] }); # [ # [0, 1], # [1, 2], # [2, 3], # [3, 4], # [4, 5], # [5, 6], # [6, 7], # [7, 8], # [8, 9], # ]
empty
empty() (Array)
The empty method drops all elements from the array.
Since 0.01
- empty example 1
-
# given: synopsis; my $empty = $array->empty; # bless({ value => [] }, "Venus::Array")
eq
eq(Any $arg) (Bool)
The eq method performs an "equals" operation using the argument provided.
Since 0.08
- eq example 1
-
package main; use Venus::Array; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->eq($rvalue); # 1
- eq example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->eq($rvalue); # 0
- eq example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->eq($rvalue); # 0
exists
exists(Int $index) (Bool)
The exists method returns true if the element at the index specified exists, otherwise it returns false.
Since 0.01
find
find(Str @keys) (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::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $find = $array->find(0, 'foo'); # { bar => "baz" }
- find example 2
-
package main; use Venus::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $find = $array->find(0, 'foo', 'bar'); # "baz"
- find example 3
-
package main; use Venus::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $find = $array->find(2, 0); # "baz"
first
first() (Any)
The first method returns the value of the first element.
Since 0.01
ge
ge(Any $arg) (Bool)
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; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->ge($rvalue); # 1
- ge example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->ge($rvalue); # 0
- ge example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->ge($rvalue); # 1
- ge example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->ge($rvalue); # 0
- ge example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->ge($rvalue); # 1
- ge example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->ge($rvalue); # 0
- ge example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->ge($rvalue); # 0
- ge example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->ge($rvalue); # 1
- ge example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->ge($rvalue); # 1
gele
gele(Any $arg1, Any $arg2) (Bool)
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; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->gele($rvalue); # 0
- gele example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->gele($rvalue); # 0
grep
grep(CodeRef $code) (ArrayRef)
The grep method executes a callback for each element in the array passing the value as an argument, returning a new array reference containing the elements for which the returned true. This method can return a list of values in list-context.
Since 0.01
- grep example 2
-
# given: synopsis; my $grep = $array->grep(sub { my ($key, $value) = @_; $value > 3 }); # [4..9]
gt
gt(Any $arg) (Bool)
The gt method performs a "greater-than" operation using the argument provided.
Since 0.08
- gt example 1
-
package main; use Venus::Array; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->gt($rvalue); # 0
- gt example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->gt($rvalue); # 0
- gt example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->gt($rvalue); # 1
- gt example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->gt($rvalue); # 0
- gt example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->gt($rvalue); # 1
- gt example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->gt($rvalue); # 0
- gt example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->gt($rvalue); # 0
- gt example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->gt($rvalue); # 1
- gt example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->gt($rvalue); # 1
gtlt
gtlt(Any $arg1, Any $arg2) (Bool)
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; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->gtlt($rvalue); # 0
- gtlt example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->gtlt($rvalue); # 0
iterator
iterator() (CodeRef)
The iterator method returns a code reference which can be used to iterate over the array. Each time the iterator is executed it will return the next element in the array 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 = $array->iterator; # sub { ... } # while (my $value = $iterator->()) { # say $value; # 1 # }
- iterator example 2
-
# given: synopsis; my $iterator = $array->iterator; # sub { ... } # while (grep defined, my ($key, $value) = $iterator->()) { # say $value; # 1 # }
join
join(Str $seperator) (Str)
The join method returns a string consisting of all the elements in the array joined by the join-string specified by the argument. Note: If the argument is omitted, an empty string will be used as the join-string.
Since 0.01
keyed
keyed(Str @keys) (HashRef)
The keyed method returns a hash reference where the arguments become the keys, and the elements of the array become the values.
Since 0.01
- keyed example 1
-
package main; use Venus::Array; my $array = Venus::Array->new([1..4]); my $keyed = $array->keyed('a'..'d'); # { a => 1, b => 2, c => 3, d => 4 }
keys
keys() (ArrayRef)
The keys method returns an array reference consisting of the indicies of the array.
Since 0.01
last
last() (Any)
The last method returns the value of the last element in the array.
Since 0.01
le
le(Any $arg) (Bool)
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; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->le($rvalue); # 1
- le example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->le($rvalue); # 1
- le example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->le($rvalue); # 0
- le example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->le($rvalue); # 0
- le example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->le($rvalue); # 0
- le example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->le($rvalue); # 1
- le example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->le($rvalue); # 0
- le example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->le($rvalue); # 0
- le example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->le($rvalue); # 0
length
length() (Int)
The length method returns the number of elements within the array, and is an alias for the "count" method.
Since 0.08
list
list() (Any)
The list method returns a shallow copy of the underlying array reference as an array reference.
Since 0.01
lt
lt(Any $arg) (Bool)
The lt method performs a "lesser-than" operation using the argument provided.
Since 0.08
- lt example 1
-
package main; use Venus::Array; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->lt($rvalue); # 1
- lt example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->lt($rvalue); # 1
- lt example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->lt($rvalue); # 0
- lt example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->lt($rvalue); # 0
map
map(CodeRef $code) (ArrayRef)
The map method iterates over each element in the array, executing the code reference supplied in the argument, passing the routine the value at the current position in the loop and returning a new array 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 = $array->map(sub { $_ * 2 }); # [2, 4, 6, 8, 10, 12, 14, 16, 18]
- map example 2
-
# given: synopsis; my $map = $array->map(sub { my ($key, $value) = @_; [$key, ($value * 2)] }); # [ # [0, 2], # [1, 4], # [2, 6], # [3, 8], # [4, 10], # [5, 12], # [6, 14], # [7, 16], # [8, 18], # ]
ne
ne(Any $arg) (Bool)
The ne method performs a "not-equal-to" operation using the argument provided.
Since 0.08
- ne example 1
-
package main; use Venus::Array; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->ne($rvalue); # 0
- ne example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->ne($rvalue); # 1
- ne example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->ne($rvalue); # 1
none
none(CodeRef $code) (Bool)
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 2
-
# given: synopsis; my $none = $array->none(sub { my ($key, $value) = @_; $value < 1 }); # 1
one
one(CodeRef $code) (Bool)
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 2
-
# given: synopsis; my $one = $array->one(sub { my ($key, $value) = @_; $value == 1 }); # 1
order
order(Int @indices) (Array)
The order method reorders the array items based on the indices provided and returns the invocant.
Since 2.01
- order example 1
-
# given: synopsis; my $order = $array->order; # bless({ value => [1..9] }, "Venus::Array")
- order example 2
-
# given: synopsis; my $order = $array->order(8,7,6); # bless({ value => [9,8,7,1,2,3,4,5,6] }, "Venus::Array")
- order example 3
-
# given: synopsis; my $order = $array->order(0,2,1); # bless({ value => [1,3,2,4,5,6,7,8,9] }, "Venus::Array")
pairs
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 = $array->pairs; # [ # [0, 1], # [1, 2], # [2, 3], # [3, 4], # [4, 5], # [5, 6], # [6, 7], # [7, 8], # [8, 9], # ]
part
part(CodeRef $code) (Tuple[ArrayRef, ArrayRef])
The part method iterates over each element in the array, executing the code reference supplied in the argument, using the result of the code reference to partition to array into two distinct array references. This method can return a list of values in list-context.
Since 0.01
- part example 2
-
# given: synopsis; my $part = $array->part(sub { my ($key, $value) = @_; $value < 5 }); # [[1..4], [5..9]]
path
path(Str $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::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $path = $array->path('/0/foo'); # { bar => "baz" }
- path example 2
-
package main; use Venus::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $path = $array->path('/0/foo/bar'); # "baz"
- path example 3
-
package main; use Venus::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my $path = $array->path('/2/0'); # "baz"
- path example 4
-
package main; use Venus::Array; my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]); my @path = $array->path('/3/0'); # (undef, 0)
pop
pop() (Any)
The pop method returns the last element of the array shortening it by one. Note, this method modifies the array.
Since 0.01
push
push(Any @data) (ArrayRef)
The push method appends the array by pushing the agruments onto it and returns itself.
Since 0.01
random
random() (Any)
The random method returns a random element from the array.
Since 0.01
- random example 1
-
# given: synopsis; my $random = $array->random; # 2 # my $random = $array->random; # 1
reverse
reverse() (ArrayRef)
The reverse method returns an array reference containing the elements in the array in reverse order.
Since 0.01
rotate
rotate() (ArrayRef)
The rotate method rotates the elements in the array such that first elements becomes the last element and the second element becomes the first element each time this method is called.
Since 0.01
rsort
rsort() (ArrayRef)
The rsort method returns an array reference containing the values in the array sorted alphanumerically in reverse.
Since 0.01
shift
shift() (Any)
The shift method returns the first element of the array shortening it by one.
Since 0.01
shuffle
shuffle() (ArrayRef)
The shuffle method returns an array with the items in a randomized order.
Since 1.40
- shuffle example 1
-
# given: synopsis package main; my $shuffle = $array->shuffle; # [4, 5, 8, 7, 2, 9, 6, 3, 1]
slice
slice(Str @keys) (ArrayRef)
The slice method returns a hash reference containing the elements in the array at the index(es) specified in the arguments.
Since 0.01
sort
sort() (ArrayRef)
The sort method returns an array reference containing the values in the array sorted alphanumerically.
Since 0.01
- sort example 1
-
package main; use Venus::Array; my $array = Venus::Array->new(['d','c','b','a']); my $sort = $array->sort; # ["a".."d"]
tv
tv(Any $arg) (Bool)
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; my $lvalue = Venus::Array->new; my $rvalue = Venus::Array->new; my $result = $lvalue->tv($rvalue); # 1
- tv example 2
-
package main; use Venus::Array; use Venus::Code; my $lvalue = Venus::Array->new; my $rvalue = Venus::Code->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 3
-
package main; use Venus::Array; use Venus::Float; my $lvalue = Venus::Array->new; my $rvalue = Venus::Float->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 4
-
package main; use Venus::Array; use Venus::Hash; my $lvalue = Venus::Array->new; my $rvalue = Venus::Hash->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 5
-
package main; use Venus::Array; use Venus::Number; my $lvalue = Venus::Array->new; my $rvalue = Venus::Number->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 6
-
package main; use Venus::Array; use Venus::Regexp; my $lvalue = Venus::Array->new; my $rvalue = Venus::Regexp->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 7
-
package main; use Venus::Array; use Venus::Scalar; my $lvalue = Venus::Array->new; my $rvalue = Venus::Scalar->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 8
-
package main; use Venus::Array; use Venus::String; my $lvalue = Venus::Array->new; my $rvalue = Venus::String->new; my $result = $lvalue->tv($rvalue); # 0
- tv example 9
-
package main; use Venus::Array; use Venus::Undef; my $lvalue = Venus::Array->new; my $rvalue = Venus::Undef->new; my $result = $lvalue->tv($rvalue); # 0
unique
unique() (ArrayRef)
The unique method returns an array reference consisting of the unique elements in the array.
Since 0.01
- unique example 1
-
package main; use Venus::Array; my $array = Venus::Array->new([1,1,1,1,2,3,1]); my $unique = $array->unique; # [1, 2, 3]
unshift
unshift(Any @data) (ArrayRef)
The unshift method prepends the array by pushing the agruments onto it and returns itself.
Since 0.01
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2000, Al Newkirk.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.