Beyond Equality: Compare

There are lots of ways to check for equality. Funx even defines a protocol for it.

This is useful in a number of situations and combines well with other protocols.

There are many situations in which you don’t merely want to say that two things are different you need to know what is different. For this I typically use a compare function that either returns :ok or a list of Validation errors.

Having a simple contract like this makes them easily composable into rulesets. Rulesets can know when it is appropriate to apply a given compare. Using this approach allows a system to provide actionable feedback. Its more than a computer says no, its a these are the problems that I have found.

This is similar to the changeset that Ecto provides for databases but at the domain model level.

Extracting composable compares and rulesets makes the domain logic explicit and testable. This will make extensions easier.