Created
October 26, 2022 17:00
-
-
Save tkersey/e3ace477291a6b1f0c720aaacf0140d2 to your computer and use it in GitHub Desktop.
Existential equality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func equals(_ lhs: Any, _ rhs: Any) -> Bool { | |
func open<A: Equatable>(_ lhs: A, _ rhs: Any) -> Bool { | |
type(of: rhs) == A.self && lhs == (rhs as? A) | |
} | |
guard let lhs = lhs as? any Equatable else { return false } | |
return open(lhs, rhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment