Skip to content

Instantly share code, notes, and snippets.

@yesleon
Created May 5, 2020 14:36
Show Gist options
  • Save yesleon/316531e0e085fbd7f74354f941f942b6 to your computer and use it in GitHub Desktop.
Save yesleon/316531e0e085fbd7f74354f941f942b6 to your computer and use it in GitHub Desktop.
enum Equality<T: Equatable> {
case equal(T)
case notEqual
}
func == <T: Equatable>(lhs: T, rhs: T) -> Equality<T> {
if lhs == rhs {
return .equal(lhs)
} else {
return .notEqual
}
}
func == <T: Equatable>(rhs: Equality<T>, lhs: T) -> Bool {
switch rhs {
case .equal(let value):
return lhs == value
case .notEqual:
return false
}
}
infix operator ==: myPrecedence
precedencegroup myPrecedence {
higherThan: AssignmentPrecedence
associativity: left
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment