It would sometimes be useful to be able to compare two functions in order to determine whether they are equal. This is famously impossible, in the general case, in the sense that there is no general algorithm to determine whether one function is equivalent to another function.
Now, when faced with the desire to test whether two functions are equal, the right answer is often: don't do that! Instead, refactor your code so that you the things you are comparing are just data.
However, there are some patterns in which you treat a function as part of a larger data type, and in those cases you may want to be able to determine whether two values of that type are equal. Hence, you want to determine whether two functions are equal.
So, how can we accommodate that, to some degree? This module provides a kind
of "wrapper" type --
EqFunc -- which can be tested for equality. The typical
- Construct an
EqFuncfrom a regular function.
- Possibly manipulate the
EqFuncor combine it with other
- Test the
EqFuncfor equality with another
runEF(and friends) to turn it back into a function.
The manipulation of an
EqFunc includes things such as composition, partial
application, currying, uncurrying, and flipping -- all preserving equality
EqFunc which has been built in an eqivalent manner.
bower install purescript-equatable-functions
Try something like:
git clone https://github.com/rgrempel/purescript-equatable-functions bower install pulp test
Documentation for the API can be found on Pursuit. Or, if you are already looking at Pursuit, then below ...