This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 145
Replace DiffAware to Hashable #36
Comments
@ton252 Hi, Hashable and Equatable are in fact useful, but I've seen it has caused some confusions, so I introduced DiffAware with |
@ton252 To avoid having to repeatedly conform types to extension DiffAware where Self: Hashable {
public var diffId: Int {
return hashValue
}
public static func compareContent(_ a: Self, _ b: Self) -> Bool {
return a == b
}
}
extension UUID: DiffAware {}
extension CGFloat: DiffAware {}
// ... This way, you can conform any type that is already Hashable to DiffAware without implementing |
Can we improve API?
I have a compile error |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Could you explain why we need to use DiffAware protocol when Hashable do the same thing and there is a lot of helper functional out-of-the-box like Hasher etc.
For example, we have a simple struct:
And if we want to conform DiffAware protocol, we need to calculate diffId something like this:
And if all the objects conformed Hashable protocol, I will not need to use map in this case and it will affect the performance.
As I remember map complexity is O(n).
The text was updated successfully, but these errors were encountered: