NAME

FP::autobox

SYNOPSIS

use FP::autobox;

is [12,4,2]->product, 96;

my $arr = [55,10];
is ref($arr), "ARRAY";

use FP::Div ":all"; use FP::Ops ":all";
is $arr->map(\&inc)->reduce(\&add), 67;

# Calling methods on arrays 'consumes' the arrays, i.e. makes them
# blessed and immutable (TODO: offer a FP::autobox::mutable or
# so?):

is ref($arr), 'FP::_::PureArray';

is( (eval { $arr->[0]++; 1 } || regex_substitute(sub{s/\s*at .*//s}, $@)),
    'Modification of a read-only value attempted' );

is $$arr[0], 55;

DESCRIPTION

Wouldn't it be cool if an ordinary Perl array could be used as an FP::Abstract::Sequence? Autobox delivers on that.

This uses autobox underneath. This module does bless the arrays, so that method calls other than in the lexical scope of the autobox import work, too.

TODO

This could be extended to support methods on strings, once a FP::String module has been implemented, and on hashes for a to-be implemented FP::Abstract::HashMap protocol.

SEE ALSO

FP::PureArray, which is transparently loaded to provide the methods.

NOTE

This is alpha software! Read the status section in the package README or on the website.