Skip to content

Instantly share code, notes, and snippets.

@tkersey
Created October 26, 2022 17:00
Show Gist options
  • Save tkersey/e3ace477291a6b1f0c720aaacf0140d2 to your computer and use it in GitHub Desktop.
Save tkersey/e3ace477291a6b1f0c720aaacf0140d2 to your computer and use it in GitHub Desktop.
Existential equality
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