---
name: "Catmandu::ArrayIterator"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::ArrayIterator"
---

# Catmandu::ArrayIterator(3pm)

Convert an arrayref to an Iterable object

## 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
