NAME

Data::Focus::Lens::HashArray::All - focus on all elements in a hash/array

SYNOPSIS

use Data::Focus qw(focus);
use Data::Focus::Lens::HashArray::All;

my $lens = Data::Focus::Lens::HashArray::All->new;
my $hash = {foo => 1, bar => 2};

my $result_hash = focus($hash)->over($lens, sub { $_[0] * 10 });

## $result_hash: {foo => 10, bar => 20}

my $array = [1, 2, 3];
my $result_array = focus($array)->over($lens, sub { $_[0] * 100 });

## $result_array: [100, 200, 300]

DESCRIPTION

Data::Focus::Lens::HashArray::All is a Data::Focus::Lens class that focuses on all elements (values) in a hash or array. If the hash or array has no element, it creates no focal point.

If the target is not a hash or array, it creates no focal point.

Elements in a hash are traversed in random order. Elements in an array are traversed from the index 0.

CLASS METHODS

$lens = Data::Focus::Lens::HashArray::All->new(%args)

The constructor. Fields in %args are:

immutable => BOOL (optional, default: false)

If set to true, the target hash/array is treated as immutable. This means every updating operation using the $lens creates a new hash/array in a copy-on-write fashion.

OBJECT METHODS

apply_lens

See Data::Focus::Lens.

AUTHOR

Toshio Ito, <toshioito at cpan.org>