Created
May 5, 2020 14:36
-
-
Save yesleon/316531e0e085fbd7f74354f941f942b6 to your computer and use it in GitHub Desktop.
This file contains 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
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