Should Dry::Struct set immutable: true on Dry::Equalizer mixin?

Greetings!

dry-equalizer 0.3.0 includes a change that adds a memoized hash method. Is there any reason not to enable this feature on Dry::Struct?

E.g. replace this:

include Dry::Equalizer(:__attributes__)

with the following:

include Dry::Equalizer(:__attributes__, immutable: true)

Might break code for anyone (ab)using Dry::Struct for mutable objects and expecting the hash method to recalculate accordingly. Seems like a remote possibility.

I have a recursive data structure (a tree) that I model with Dry::Struct subclass instances; by including the Dry::Equalizer module as above directly in my subclasses, the average invocation of hash dropped from 3.25 sec to under 20ms.

1 Like

Yes, this makes sense. I’ll add it as an option with true by default later this week. I plan to run it here and there for some time and cut a release some time next week.

1 Like

Awesome. Thanks for the response!