Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
6.24k stars 199 forks source link

Equal in 4.0 (Proposal) #2855

Open mikearnaldi opened 1 month ago

mikearnaldi commented 1 month ago

I propose to change how equality works in 4.0 to be more structural by default, the idea would be:

1) consider plain objects, arrays, sets and maps structurally 2) consider non plain objects (prototype !== Object.prototype) by reference 3) provide a byReference function backed by a weakmap to consider an instance of an object as by reference

We previously backed off from structural by default due to errors with circular structures but this was mainly due to considering ALL objects structurally (i.e. also custom classes). We should also be able to deal with circular structures by detecting loops.

datner commented 1 month ago

Does this mean that equals(new Thing(),new Thing()) will be false? 🤔

mikearnaldi commented 1 month ago

Does this mean that equals(new Thing(),new Thing()) will be false? 🤔

depends how Thing is defined, not if it is defined via Data