-
-
24 May 2021 11:36:26 UTC
- Distribution: FunctionalPerl
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (100 / 2 / 13)
- Kwalitee
Bus factor: 1- License: perl_5
- Perl: v5.16.4
- Activity
24 month- Tools
- Download (443.46KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Christian Jaeger
- Dependencies
- Digest
- File::Path
- Getopt::Long
- Import::Into
- Math::BigInt
- NEXT
- PerlIO::utf8_strict
- Safe::Isa
- Scalar::Util
- Symbol
- Test::More
- autobox
- base
- overload
- utf8
- warnings
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
FP::PureArray
SYNOPSIS
use FP::PureArray; use FP::Div 'inc'; my $a = purearray(1,4,5)->map(\&inc); is $a->sum, 13; # can't mutate it: like( (eval { $a->[0]++; 1 } || $@), qr/^Modification of a read-only value attempted/); like( (eval { push @$a, 123; 1 } || $@), qr/^Modification of a read-only value attempted/); is $a->sum, 13; my $b = $a->unsafe_mutable; # efficient but dangerous! $$b[0]++; is $a->sum, 14; # said it was dangerous! is ref($a), 'FP::_::MutableArray'; # see FP::MutableArray is( FP::_::PureArray->null == FP::_::PureArray->null, 1);
DESCRIPTION
Perl arrays blessed into the `FP::PureArray` package, inheriting from `FP::Abstract::Pure`, and coming with the functions from `FP::Array` as methods.
If you hand someone an FP::PureArray you guarantee that you won't mutate it. This might be enforced in the future by making them immutable (todo).
PURITY
`PureArray`s are created to be immutable by default, which enforces the functional purity of the API. This can be disabled by setting `$FP::PureArray::immutable` to false when creating them. Only ever use this during development, if at all. If you need to have efficient updates, use another data structure (FP::List suits many cases, or the to-be written FP::Vec, although at that point updates directly on PureArray may be implemented efficiently, too). Or if you're sure making a PureArray mutable again is safe, you can call the `unsafe_mutable` method. Should lexical analysis get implemented in Perl at some point, a method `mutable` could be offered that safely (by way of checking via the reference count that there are no other users) turns a PureArray back into a mutable array.
PureArray implements `FP::Abstract::Pure` (`is_pure` from `FP::Predicates` returns true even if instances were made mutable via setting `$FP::PureArray::immutable`). Values returned from `unsafe_mutable` are in a different class which does *not* implement `FP::Abstract::Pure`.
TODO
Create alternative implementation that is efficient for updates on big arrays (perhaps to be called FP::Vec, but to be interoperable).
SEE ALSO
Implements: FP::Abstract::Pure, FP::Abstract::Sequence, FP::Abstract::Equal, FP::Abstract::Show
NOTE
This is alpha software! Read the status section in the package README or on the website.
Module Install Instructions
To install FunctionalPerl, copy and paste the appropriate command in to your terminal.
cpanm FunctionalPerl
perl -MCPAN -e shell install FunctionalPerl
For more information on module installation, please visit the detailed CPAN module installation guide.