NAME
Data::Object::Array
ABSTRACT
Data-Object Array Class
SYNOPSIS
use Data::Object::Array;
my $array = Data::Object::Array->new([1..9]);
DESCRIPTION
This package provides routines for operating on Perl 5 array references.
INHERITANCE
This package inherits behaviors from:
INTEGRATIONS
This package integrates behaviors from:
LIBRARIES
This package uses type constraints defined by:
METHODS
This package implements the following methods.
all
all(CodeRef $arg1, Any @args) : NumObject
The all method returns true if all of the elements in the array meet the criteria set by the operand and rvalue. This method returns a Data::Object::Number object.
- all example
-
# given [2..5] $array->all(fun ($value, @args) { $value > 1; # 1, true }); $array->all(fun ($value, @args) { $value > 3; # 0; false });
any
any(CodeRef $arg1, Any @args) : NumObject
The any method returns true if any of the elements in the array meet the criteria set by the operand and rvalue. This method returns a Data::Object::Number object.
- any example
-
# given [2..5] $array->any(fun ($value) { $value > 5; # 0; false }); $array->any(fun ($value) { $value > 3; # 1; true });
clear
clear() : Object
The clear method is an alias to the empty method. This method returns a Data::Object::Undef object. This method is an alias to the empty method. Note: This method modifies the array.
count
count() : NumObject
The count method returns the number of elements within the array. This method returns a Data::Object::Number object.
defined
defined() : NumObject
The defined method returns true if the element within the array at the index specified by the argument meets the criteria for being defined, otherwise it returns false. This method returns a Data::Object::Number object.
- defined example
-
# given [1,2,undef,4,5] $array->defined(2); # 0; false $array->defined(1); # 1; true
delete
delete(Int $arg1) : Any
The delete method returns the value of the element within the array at the index specified by the argument after removing it from the array. This method returns a data type object to be determined after execution. Note: This method modifies the array.
each
each(CodeRef $arg1, Any @args) : Object
The each method iterates over each element in the array, executing the code reference supplied in the argument, passing the routine the index and value at the current position in the loop. This method returns a Data::Object::Array object.
each_key
each_key(CodeRef $arg1, Any @args) : Object
The each_key method iterates over each element in the array, executing the code reference supplied in the argument, passing the routine the index at the current position in the loop. This method returns a Data::Object::Array object.
each_n_values
each_n_values(Num $arg1, CodeRef $arg2, Any @args) : Object
The each_n_values method iterates over each element in the array, executing the code reference supplied in the argument, passing the routine the next n values until all values have been seen. This method returns a Data::Object::Array object.
- each_n_values example
-
# given ['a'..'g'] $array->each_n_values(4, fun (@values) { $values[1] # a $values[2] # b $values[3] # c $values[4] # d ... });
each_value
each_key(CodeRef $arg1, Any @args) : Object
The each_value 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. This method returns a Data::Object::Array object.
empty
empty() : Object
The empty method drops all elements from the array. This method returns a Data::Object::Array object. Note: This method modifies the array.
eq
eq(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
exists
exists(Int $arg1) : NumObject
The exists method returns true if the element within the array at the index specified by the argument exists, otherwise it returns false. This method returns a Data::Object::Number object.
first
first() : Any
The first method returns the value of the first element in the array. This method returns a data type object to be determined after execution.
ge
ge(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
get
get(Int $arg1) : Any
The get method returns the value of the element in the array at the index specified by the argument. This method returns a data type object to be determined after execution.
grep
grep(CodeRef $arg1, Any @args) : ArrayObject
The grep 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 evaluated true. This method returns a Data::Object::Array object.
gt
gt(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
hash
hash() : HashObject
The hash method returns a hash reference where each key and value pairs corresponds to the index and value of each element in the array. This method returns a Data::Object::Hash object.
hashify
hashify(CodeRef $arg1, Any $arg2) : HashObject
The hashify method returns a hash reference where the elements of array become the hash keys and the corresponding values are assigned a value of 1. This method returns a Data::Object::Hash object.
- hashify example
-
# given [1..5] $array->hashify; # {1=>1,2=>1,3=>1,4=>1,5=>1} $array->hashify(fun ($value) { $value % 2 }); # {1=>1,2=>0,3=>1,4=>0,5=>1}
head
head() : Any
The head method returns the value of the first element in the array. This method returns a data type object to be determined after execution.
invert
invert() : Any
The invert method returns an array reference containing the elements in the array in reverse order. This method returns a Data::Object::Array object.
iterator
iterator() : CodeObject
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 returns a Data::Object::Code object.
- iterator example
-
# given [1..5] my $iterator = $array->iterator; while (my $value = $iterator->next) { say $value; # 1 }
join
join(Str $arg1) : StrObject
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. This method returns a Data::Object::String object.
keyed
keyed(Str $arg1) : HashObject
The keyed method returns a hash reference where the arguments become the keys, and the elements of the array become the values. This method returns a Data::Object::Hash object.
keys
keys() : ArrayObject
The keys method returns an array reference consisting of the indicies of the array. This method returns a Data::Object::Array object.
last
last() : Any
The last method returns the value of the last element in the array. This method returns a data type object to be determined after execution.
le
le(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
length
length() : NumObject
The length method returns the number of elements in the array. This method returns a Data::Object::Number object.
list
list() : ArrayObject
The list method returns a shallow copy of the underlying array reference as an array reference. This method return a Data::Object::Array object.
lt
lt(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
map
map(CodeRef $arg1, Any $arg2) : ArrayObject
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 returns a Data::Object::Array object.
max
max() : Any
The max method returns the element in the array with the highest numerical value. All non-numerical element are skipped during the evaluation process. This method returns a Data::Object::Number object.
min
min() : Any
The min method returns the element in the array with the lowest numerical value. All non-numerical element are skipped during the evaluation process. This method returns a Data::Object::Number object.
ne
ne(Any $arg1) : NumObject
This method is a consumer requirement but has no function and is not implemented. This method will throw an exception if called.
none
none(CodeRef $arg1, Any $arg2) : NumObject
The none method returns true if none of the elements in the array meet the criteria set by the operand and rvalue. This method returns a Data::Object::Number object.
- none example
-
# given [2..5] $array->none(fun ($value) { $value <= 1; # 1; true }); $array->none(fun ($value) { $value <= 2; # 0; false });
nsort
nsort() : ArrayObject
The nsort method returns an array reference containing the values in the array sorted numerically. This method returns a Data::Object::Array object.
one
one(CodeRef $arg1, Any $arg2) : NumObject
The one method returns true if only one of the elements in the array meet the criteria set by the operand and rvalue. This method returns a Data::Object::Number object.
- one example
-
# given [2..5] $array->one(fun ($value) { $value == 5; # 1; true }); $array->one(fun ($value) { $value == 6; # 0; false });
pairs
pairs() : ArrayObject
The pairs method is an alias to the pairs_array method. This method returns a Data::Object::Array object. This method is an alias to the pairs_array method.
pairs_array
pairs() : ArrayObject
The pairs_array method returns an array reference consisting of array references where each sub-array reference has two elements corresponding to the index and value of each element in the array. This method returns a Data::Object::Array object.
pairs_hash
pairs() : ArrayObject
The pairs_hash method returns a hash reference where each key and value pairs corresponds to the index and value of each element in the array. This method returns a Data::Object::Hash object.
part
part(CodeRef $arg1, Any $arg2) : 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 returns an array reference containing exactly two array references. This method returns a Data::Object::Array object.
- part example
-
# given [1..10] $array->part(fun ($value) { $value > 5 }); # [[6, 7, 8, 9, 10], [1, 2, 3, 4, 5]]
pop
pop() : Any
The pop method returns the last element of the array shortening it by one. Note, this method modifies the array. This method returns a data type object to be determined after execution. Note: This method modifies the array.
push
push(Any $arg1) : Any
The push method appends the array by pushing the agruments onto it and returns itself. This method returns a data type object to be determined after execution. Note: This method modifies the array.
random
random() : NumObject
The random method returns a random element from the array. This method returns a data type object to be determined after execution.
reverse
reverse() : ArrayObject
The reverse method returns an array reference containing the elements in the array in reverse order. This method returns a Data::Object::Array object.
rnsort
rnsort() : ArrayObject
The rnsort method returns an array reference containing the values in the array sorted numerically in reverse. This method returns a Data::Object::Array object.
rotate
rotate() : ArrayObject
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. This method returns a Data::Object::Array object. Note: This method modifies the array.
- rotate example
-
# given [1..5] $array->rotate; # [2,3,4,5,1] $array->rotate; # [3,4,5,1,2] $array->rotate; # [4,5,1,2,3]
rsort
rsort() : ArrayObject
The rsort method returns an array reference containing the values in the array sorted alphanumerically in reverse. This method returns a Data::Object::Array object.
self
self() : Object
The self method returns the calling object (noop).
set
set(Str $arg1, Any $arg2) : Any
The set method returns the value of the element in the array at the index specified by the argument after updating it to the value of the second argument. This method returns a data type object to be determined after execution. Note: This method modifies the array.
shift
shift() : Any
The shift method returns the first element of the array shortening it by one. This method returns a data type object to be determined after execution. Note: This method modifies the array.
size
size() : NumObject
The size method is an alias to the length method. This method returns a Data::Object::Number object. This method is an alias to the length method.
slice
kvslice(Any @args) : HashObject
The kvslice method returns a hash reference containing the elements in the array at the index(es) specified in the arguments. This method returns a Data::Object::Hash object.
slice
slice(Any $arg1) : Any
The slice method returns an array reference containing the elements in the array at the index(es) specified in the arguments. This method returns a Data::Object::Array object.
sort
sort() : ArrayObject
The sort method returns an array reference containing the values in the array sorted alphanumerically. This method returns a Data::Object::Array object.
sum
sum() : NumObject
The sum method returns the sum of all values for all numerical elements in the array. All non-numerical element are skipped during the evaluation process. This method returns a Data::Object::Number object.
tail
tail() : Any
The tail method returns an array reference containing the second through the last elements in the array omitting the first. This method returns a Data::Object::Array object.
unique
unique() : ArrayObject
The unique method returns an array reference consisting of the unique elements in the array. This method returns a Data::Object::Array object.
unshift
unshift() : Any
The unshift method prepends the array by pushing the agruments onto it and returns itself. This method returns a data type object to be determined after execution. Note: This method modifies the array.
values
values() : ArrayObject
The values method returns an array reference consisting of the elements in the array. This method essentially copies the content of the array into a new container. This method returns a Data::Object::Array object.
CREDITS
Al Newkirk, +319
Anthony Brummett, +10
Adam Hopkins, +2
José Joaquín Atria, +1
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated here, https://github.com/iamalnewkirk/do/blob/master/LICENSE.
PROJECT
SEE ALSO
To get the most out of this distribution, consider reading the following: