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
fix: iterable equality comparisons #103
Conversation
Hi @felangel Can you please tell me if there is a way to solve this problem for manually overriding the |
Hi @nxtSwitch 👋 Can you provide a bit more context or a reproduction sample? I'm not sure I understand the use-case/question. |
А similar case, but without using the equatable: class SimpleEquatable<T> extends Equatable {
const SimpleEquatable(this.data);
final T data;
@override
List<Object> get props => [data];
}
@immutable
class IterableWithFlag extends Iterable<String> {
final bool flag;
final List<String> list;
const IterableWithFlag({this.list, this.flag});
@override
bool operator ==(Object other) {
return identical(this, other) ||
other is IterableWithFlag && flag == other.flag;
}
@override
Iterator<String> get iterator => list.iterator;
} const instanceA = IterableWithFlag(list: ['1', '2'], flag: true);
const instanceB = IterableWithFlag(list: ['1', '2'], flag: false);
print(const SimpleEquatable(instanceA) == const SimpleEquatable(instanceB)); // true |
@nxtSwitch I believe the reason why that isn't working is because two Iterable instances are considered equal if they have the same elements in the same order. I wouldn't recommend having a custom @immutable
class Iterable extends Iterable<String> {
final List<String> list;
const IterableWithFlag({this.list});
@override
Iterator<String> get iterator => list.iterator;
}
class FlagWrapper<T> {
final T data;
final bool flag;
const FlagWrapper({this.data, this.flag});
@override
bool operator ==(Object other) {
return identical(this, other) ||
other is FlagWrapper<T> && flag == other.flag && data == other.data;
}
} Hope that helps 👍 |
I might make an issue, but It's maked as fixed, so I can't sure It's my problem or not. I have a test that used equatable but failed on nested iterable. Logs:
The related classes:
The generator method
If I change the generator method to the following, the test passed...
Or make the Any help would be appreciated! Edit:
to
For whom stuck on nested iterable, I think here is the solution, might not be the best. |
Status
READY
Breaking Changes
NO
Description
Todos