Package DE_EPAGES::Core::API::Iterator
Iterator pattern
Example |
my ($i, $Count) = (0, 1000); my $DynamicSquareIterator = DE_EPAGES::Core::API::Iterator->new( Pull => sub { return $i <= $Count ? $i++ : undef }, Count => $Count, Handle => sub { $_[1] * $_[1] } ); while( my $Square = <$DynamicSquareIterator> ) { print "$Square\n"; } |
@EXPORT_OK |
Functions
ArrayIterator
Creates an iterator from an array reference.
Syntax |
$Iterator = ArrayIterator( $aArray ); $Iterator = ArrayIterator( $aArray, $Handle ); |
Input |
|
Return |
|
count
returns the total number of items in the iterator. Note: not all iterators can determine the item count in advance.
Syntax |
$Count = $Iterator->count; |
Return |
|
new
creates an iterator object
Syntax |
$Iterator = DE_EPAGES::Core::API::Iterator->new( %Options ) |
Input |
|
Return |
|
next
returns the next item from the iterator. Returns undef after the last item.
Syntax |
$Item = $Iterator->next; |
Return |
|
wrap
creates an iterator object by wrapping an existing iterator
Syntax |
$Iterator = DE_EPAGES::Core::API::Iterator->wrap( %Options ) |
Example |
my $Iterator = DE_EPAGES::Core::API::Iterator->wrap( Source => ArrayIterator( [ 1..9 ] ), Handle => sub { $_[1] * $_[1] } ); |
Input |
|
Return |
|