Array:...tional(3pm)

πŸ’– Array::Iterator::BiDirectional β€” the man page, but make it a group chat

okay bestie, so this is the manual page for Array::Iterator::BiDirectional πŸ’… (the header up top squishes it down to Array:...tional(3pm) but you and me both know the full name). It's a Perl module, it lives in the 3pm section, and it's here to let your iterators walk backwards as well as forwards. Iconic behaviour, honestly. πŸ¦‹


✨ VERSION ✨

Version 0.136 β€” that's the one, no cap.


🌸 SYNOPSIS 🌸

okay so picture this: sometimes an iterator lowkey needs to go both directions, forward and backward. The classic example is token processing β€” you're looping through tokens and sometimes you gotta advance forward hunting for a match to a rule, and if that match fails, a bi-directional iterator can just go back so the next rule gets a turn. Chef's kiss. πŸ‘‘

use Array::Iterator::BiDirectional;

# create an instance of the iterator
my $i = Array::Iterator::BiDirectional->new(1 .. 100);

while ($some_condition_exists) {
    # get the latest item from
    # the iterator
    my $current = $i->get_next();
    # ...
    if ($something_happens) {
        # back up the iterator
        $current = $i->get_previous();
    }
}

πŸ’… METHODS πŸ’…

Real talk: this is a subclass of Array::Iterator, so only the methods that got added are documented down here. For everything else, go read the Array::Iterator documentation, fr fr. πŸ“š

  • has_previous([$n]) β€” works a lot like hasNext does. It returns true (1) unless you've hit the beginning of the array, and false (0) otherwise. The optional argument means the same kind of thing, except it's specifying the $nth previous element. πŸŽ€
  • previous β€” much like next. It hands you the previous item in the iterator, and it throws an exception if it tries to reach past the beginning of the array. No quietly sneaking off the edge, bestie. 😭
  • get_previous β€” much like get_next. It returns the previous item in the iterator, and returns undef if it attempts to reach past the beginning of the array. Chill about it, no exception. 🫢
  • look_back([$n]) β€” this is the counterpart to peek. It returns the previous items in the iterator but will not affect the internal counter β€” pure vibes, no side effects. ✨ The optional argument means the same kind of thing, except it specifies the $nth previous element.

🌈 SEE ALSO 🌈

This is a subclass of Array::Iterator β€” please refer to it for more documentation. It's giving "found family", honestly. πŸ’œ


πŸ‘‘ MAINTAINER πŸ‘‘

Nigel Horne, "<njh at nigelhorne.com>"

2025-2026


πŸŽ€ ORIGINAL AUTHOR πŸŽ€

stevan little, <stevan@iinteractive.com>


Copyright 2004 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole thing, you ate that πŸ“ β€” and just so you have the receipts: this was perl v5.40.1, dated 2026-03-11, on the Array:...tional(3pm) page. mwah πŸ’‹

πŸ“¦ where this page comes from