collection
collection copied to clipboard
Add an option (possibly the default?) for DeepCollectionEquality to handle self-referential structures
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="96" height="96"hspace="10"> Issue by nex3 Originally opened as dart-lang/sdk#18729
Sometimes it's useful to be able to compare nested object structures that can contain self-referential loops. Currently DeepCollectionEquality causes a stack overflow when passed such structures, but it would be nice if it could handle them. This could be done either as a configuration option or as the default if the prospect of storing back-references isn't too worrisome.
Currently the YAML package has its own custom implementation of deep equality, but it would be nice if it could use the standard implementation instead.
<img src="https://avatars.githubusercontent.com/u/4865287?v=3" align="left" width="48" height="48"hspace="10"> Comment by lrhn
That should be doable. For each operand, remember each object it is currently being compared to, and if you see that combination again, return true. It's not fool-proof, but it will catch most simple self-referential structures.
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3
I believe YAML's deepEquals operation works like that, but it remembers the order of the objects it's being compared to as well.
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo
Aligning w/ the bits offered from matcher would be nice, too.
Fewer implementations FTW
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3
Matcher's use case is a little different, because it needs to track a bunch of extra information to provide useful messaging when the equality fails.
This has been open since 2015 without action so I am closing as stale.
@matanlurey I appreciate your zeal for cleaning up the issue tracker, but it's useful for me as a maintainer of this package to track features that would be useful to users, even if I don't often get a chance to work on those features. As long as these features would still be useful, I'd like to keep the tracking issues open.
I don't want to make the existing deep equality check for cycles. That's a lot of work (and memory for caching) which has no effect in most cases.
We can add another equivalence which does handle cycles, if we want to.