FP::Abstract::Equal - equality protocol
package FPEqualExample::Foo { sub new { my $class = shift; bless [@_], $class } sub FP_Equal_equal { my ($a, $b) = @_; # If you know you've got numbers in here only: $$a[0] == $$b[0] # For generic values, you would instead: #use FP::Equal; #equal($$a[0], $$b[0]) } } use FP::Equal qw(equal); use FP::List; ok equal( list(10,20,30)->map (sub{ equal(FPEqualExample::Foo->new(20), FPEqualExample::Foo->new($_[0])) }), list('', 1, ''));
Objects implementing this protocol can be compared using the functions from FP::Equal, primarily equal.
equal
The equal function forces promises before doing further comparisons or passing them to the FP_Equal_equal method (only the immediate layer, not deeply). FP_Equal_equal is only ever called with the two arguments (self and one method argument) being references of, currently, the same type (equal handles the other cases internally) (TODO: how to handle subtypes?). In better(?) words, FP_Equal_equal implementations can rely on the second argument supporting the same operations that the first one does (TODO: even into the future once accepting subtyping? This is *alpha*.) Likewise, FP_Equal_equal is not called if the arguments are both the same reference (in this case equal simply returns true).
FP_Equal_equal
Handle circular data structures.
FP::Equal
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.