NAME

Module::Generic::Iterator - An Array Iterator Object Class

SYNOPSIS

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  );
}

VERSION

v1.1.1

DESCRIPTION

This provides an object oriented array iterator. Each of its elements are Module::Generic::Iterator::Element object

METHODS

new

Provided with an array reference or an Module::Generic::Array object, and this will create a new iterator and return it.

elements

Contains the array elements

eof

Returns true if the position in the iterator has reached the end of the array.

find

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.

first

Returns the first element of the array.

has_next

Returns true if there is another item after the current one.

has_prev

Returns true if there is another item before the current one.

last

Returns the last element of the array.

length

Returns the size of the array, starting from 1, as a Module::Generic::Number object.

next

Returns the next Module::Generic::Iterator::Element object or undef if there are no more element.

pos

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

prev

Returns the previous Module::Generic::Iterator::Element object or undef if there are no more previous element.

reset

Reset the position inside the array and sets it to 0.

_find_pos

Provided with an item, this returns its position in the array or undef if it is not in the array.

SERIALISATION

Serialisation by CBOR, Sereal and Storable::Improved (or the legacy Storable) is supported by this package. To that effect, the following subroutines are implemented: FREEZE, THAW, STORABLE_freeze and STORABLE_thaw

SEE ALSO

Module::Generic::Iterator::Element, Module::Generic::Array

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright (c) 2000-2024 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.