Blast-Radius Aware AI Code Review for Business-Critical Systems
LiveReview LiveReview Explore LiveReview

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

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.

Name

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

See Also

       Catmandu::Iterable, Catmandu::Iterator

perl v5.40.0                                       2025-01-17                       Catmandu::ArrayIterator(3pm)

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

See Also