List::Rotation::Cycle(3pm)

List::Rotation::Cycle3pm

Cycle through a list of values via a singleton object implemented as closure.

Usage

    use List::Rotation::Cycle;
    my @array = qw( A B C );
    my $first_cycle  = List::Rotation::Cycle->new(@array);
    my $second_cycle = List::Rotation::Cycle->new(@array);
    print $first_cycle->next;  ## prints A
    print $second_cycle->next; ## prints B
    print $first_cycle->next;  ## prints C
    print $second_cycle->next; ## prints A, looping back to beginning

Overview

Use "List::Rotation::Cycle" to loop through a list of values. Once you get to the end of the list, you go back to the beginning.

"List::Rotation::Cycle" is implemented as a Singleton Pattern. You always just get 1 (the very same) Cycle object even if you use the new method several times. This is done by using "Memoize" on the "new" method. It returns the same object for every use of "new" that comes with the same List of parameters.

Object methods

new

Create a Cycle object for the list of values in the list.

next

Return the next element. This method is implemented as a closure.

Releases

6 releases since Debian 8 (Jessie); the text changed 2 times.

  1. 8–10
  2. 11
  3. 12–13

Author

Imre Saling, "<pelagicatcpandotorg>"

From liblist-rotation-cycle-perl 1.009-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.