Last active
February 27, 2024 20:57
-
-
Save phranck/ee629a99e71899f59abcbe3c8848516a 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
/// The `=!=` operator assigns the value on the right-hand side to the variable on the left-hand side | |
/// only if the two values are not equal. This operator is designed for types conforming to the `Equatable` protocol. | |
/// | |
/// - Parameters: | |
/// - lhs: The variable to be assigned a new value if not equal. | |
/// - rhs: The value to be assigned to the variable if it is not equal to the current value. | |
/// | |
/// - Precondition: The type of the operands must conform to the `Equatable` protocol. | |
/// | |
/// - Precedence: `AssignIfNotEqualPrecedence` | |
/// | |
/// - Complexity: O(1) | |
/// | |
/// - Note: The assignment operation is performed only if `lhs != rhs`. | |
/// | |
/// - Example: | |
/// ```swift | |
/// var x = 42 | |
/// let y = 24 | |
/// x =!= y // x is now 24 | |
/// ``` | |
/// | |
infix operator =!=: AssignIfNotEqualPrecedence | |
public func =!=<T>(lhs: inout T, rhs: T) where T: Equatable { | |
if lhs != rhs { lhs = rhs } | |
} | |
precedencegroup AssignIfNotEqualPrecedence { | |
lowerThan: ComparisonPrecedence | |
higherThan: AssignmentPrecedence | |
associativity: left | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment