Module::Generic::Iterator - An Array Iterator Object Class
my $i = Module::Generic::Iterator->new( [qw( Joe John Mary )] ); # or also: my $a = Module::Generic::Array->new( [qw( Joe John Mary )] ); my $i = $a->iterator; while( $i->has_next ) { my $elem = $i->next; my $value = $elem->value; # Get the next element relative to our element printf( "Next value is: %s at offset %d\n", $elem->next, $elem->next->pos ); }
v1.0.0
This provides an object oriented array iterator. Each of its elements are Module::Generic::Iterator::Element object
Provided with an array reference or an Module::Generic::Array object, and this will create a new iterator and return it.
Contains the array elements
Returns true if the position in the iterator has reached the end of the array.
Creates a clone of the current array object and returns it.Provided wit an array element and this returns its position in the array starting at 0.
If nothing was found, this returns undef.
Returns the first element of the array.
Returns true if there is another item after the current one.
Returns true if there is another item before the current one.
Returns the last element of the array.
Returns the size of the array, starting from 1, as a Module::Generic::Number object.
Returns the next Module::Generic::Iterator::Element object or undef if there are no more element.
Sets or returns the current position in the array.
This is an lvalue method.
$e->pos = 10; # Sets the current position to 10 my $pos = $e->pos; # Returns the current position
Returns the previous Module::Generic::Iterator::Element object or undef if there are no more previous element.
Reset the position inside the array and sets it to 0.
Provided with an item, this returns its position in the array or undef if it is not in the array.
Module::Generic::Iterator::Element, Module::Generic::Array
Jacques Deguest <jack@deguest.jp>
Copyright (c) 2000-2020 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install Module::Generic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Generic
CPAN shell
perl -MCPAN -e shell install Module::Generic
For more information on module installation, please visit the detailed CPAN module installation guide.