NAME
Number::Range::Regex::Iterator - create iterators for Number::Range::Regex objects
SYNOPSIS
use Number::Range::Regex;
my $it = rangespec( '-5..-3,3..5' )->iterator();
$it->first();
do {
do_something_with_value( $it->fetch );
} while ($it->next);
$it->last();
do {
do_something_with_value( $it->fetch );
} while ($it->prev);
METHODS
- new
-
$it = Number:Range::Regex::Iterator->new( $range );
given a range, return an iterator that returns its members. note that this is identical to the more compact, usual form:
$range->iterator()
- fetch
-
return the integer currently pointed to by the iterator.
- first
-
$range->first();
set the iterator to point at its lowest value. first() will throw an error if called on a range with no lower bound, for example:
range( undef, $n )->iterator->first;
- last
-
$range->last();
set the iterator to point at its greatest value. last() will throw an error if called on a range with no upper bound, for example:
rangespec( '3..inf' )->iterator->first;
- next
-
point to the next greatest integer that is part of $range. often this value will be one greater, but in the case of compound ranges, it will not always. consider:
my $it = range( '4,22..37' )->iterator; $it->first; # $it->fetch == 4 $it->next; # $it->fetch == 22
- prev
-
$range->prev()
point to the next smallest integer that is part of $range. often this value will be one smaller, but not always:
my $it = range( '22..37,44' )->iterator; $it->last; # $it->fetch == 44 $it->prev; # $it->fetch == 37
- seek
-
$range->iterator->seek( $n );
set the iterator to point to the value $n in $range. that is:
$it->seek( $n )->fetch == $n
if $n is not member of $range, seek() throws an error.
- size
-
$range->size();
Returns the size of the iterator. If the iterator is unbounded, returns undef.
- in_range
-
$range->in_range();
returns a boolean value indicating whether $range has been set to a valid position with any of the methods first, last, seek, prev, and next. returns false in e.g. the following circumstances: $range->last->next; $range->first->prev; range( '3..4' )->first->next->next; range( '3..4' )->last->prev->prev;
BUGS AND LIMITATIONS
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
AUTHOR
Brian Szymanski <ski-cpan@allafrica.com> -- be sure to put Number::Range::Regex in the subject line if you want me to read your message.
SEE ALSO
Number::Range::Regex