The essential quality of a “pure” function is that it always has the same output for the same inputs.
You could make your function pure by passing in the state of the database and returning the state of the database, However, that’s not really practical. But you should strive to have anything you operate on in the function passed in as an input, rather that magically appearing from the ether.
def delete(DB, values ) do
Kernal.apply(DB, :delete_all, values )
end
This makes the code much easier to test and also limits the side effects to as small a surface area as possible. There is obviously a trade-off between adding needless complexity and applying this principle. To misquote Terry Pratchett
That’s why there are rules, so you’ll think a bit before you break them.






















