Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added deep collection equality for signal comparison #256

Merged
merged 4 commits into from Apr 26, 2024

Conversation

leoafarias
Copy link
Contributor

Issue: #243

This will be a two part PR:

This adds a new utility class DeepCollectionEquality to the signals_core package. The class provides a way to compare the equality of complex data structures, such as maps, sets, and iterables, by recursively comparing their elements.

The DeepCollectionEquality class includes:

  1. equals method: Compares two objects for deep equality, handling maps, sets, and iterables.
  2. _mapsEqual method: Compares two maps for deep equality.
  3. _iterablesEqual method: Compares two iterables for deep equality, considering element order.
  4. _setsEqual method: Compares two sets for deep equality.

Example usage:

final deepEquality = DeepCollectionEquality();
final map1 = {'a': 1, 'b': [2, 3]};
final map2 = {'b': [2, 3], 'a': 1};
print(deepEquality.equals(map1, map2)); // Output: true

If things look good so far, let me know where you would like to add the functionality and I can give it a go.

Copy link
Owner

@rodydavis rodydavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rodydavis
Copy link
Owner

Do we need unordered list/set comparisons? Or just have a method to pass in that can override this implementation?

@leoafarias
Copy link
Contributor Author

@rodydavis overriding will be your call. Initially I am trying to kep it consistent with flutter foundation library.

set: https://api.flutter.dev/flutter/foundation/setEquals.html
map: https://api.flutter.dev/flutter/foundation/mapEquals.html
list: https://api.flutter.dev/flutter/foundation/listEquals.html

@rodydavis
Copy link
Owner

Works for me! I was meaning like a static override on the class but could be added in a later PR

@rodydavis
Copy link
Owner

Also we can make the members public so the class can be extended and overridden.

Maybe the name could be prefixed with Signals too

@rodydavis rodydavis merged commit cd1711f into rodydavis:main Apr 26, 2024
2 checks passed
@leoafarias
Copy link
Contributor Author

Hey @rodydavis let me know how you want to proceed with the remaining changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants