FP::autobox
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;
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.
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.
FP::PureArray, which is transparently loaded to provide the methods.
This is alpha software! Read the status section in the package README or on the website.
To install FunctionalPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FunctionalPerl
CPAN shell
perl -MCPAN -e shell install FunctionalPerl
For more information on module installation, please visit the detailed CPAN module installation guide.