NAME

FP::Equals - generic equality comparison

SYNOPSIS

use FP::Equals;
use FP::List;
use FP::Div qw(inc);
equals [1, list(2, 3)], [1, list(1, 2)->map(*inc)]; # -> 1
equals [1, list(2, 3)], [1, list(1, 2)]; # -> ''
equals [1, list(2, 3)], [1, list([], 3)]; # -> undef: "not the same type"

DESCRIPTION

Deep, generic (but class controlled) structure equality comparison.

Non-objects are hard coded in this module. Objects are expected to have an `FP_Equals_equals` method that is able to take an argument of the same class as the object to compare (if it doesn't have such an object, it simply can't be compared using this module).

This does *name based* type comparison: structurally equivalent objects do not count as equal if they do not have the same class (or more general, reference name), the `FP_Equals_equals` method is not even called; the equals function returns undef in this case. This might be subject to change: certain pairs of types will be fine to compare; let the classes provide a method that checks whether a type is ok to compare?

TODO

- cycle detection

- immutable version -> equals_now equals_forever

- do we need the possibility for "context" dependent (and not by way of subclassing and overriding equals_*) equality comparisons?

SEE ALSO

FP::Equal for a non-class controlled alternative

FP::Show