++ed by:
VOJ

1 PAUSE user(s)
3 non-PAUSE user(s).

Nicolas Steenlant

NAME

Catmandu::ArrayIterator - Convert an arrayref to an Iterable object

SYNOPSIS

    use Catmandu::ArrayIterator;

    my $it = Catmandu::ArrayIterator->new([{n => 1}, {n => 2}, {n => 3}]);

    $it->each( sub {
        my $item = $_[0];
        # Very complicated routine
      ....
    });

    $it->[0];
    # => {n => 1}
    $it->first;
    # => {n => 1}
    $it->map(sub { $_[0]->{n} + 1 })->to_array;
    # => [2, 3, 4]
    $it->count
    # => 3

METHODS

new($arrayRef)

Create a new iterator object from $arrayRef.

to_array

Return all the items in the Iterator as an ARRAY ref.

each(\&callback)

For each item in the Iterator execute the callback function with the item as first argument. Returns the number of items in the Iterator.

count

Return the count of all the items in the Iterator.

first

Return the first item from the Iterator.

SEE ALSO

Catmandu::Iterable, Catmandu::Iterator




Hosting generously
sponsored by Bytemark