Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Last active February 5, 2024 22:40
Show Gist options
  • Save el-hoshino/52287f710b48d3890a3151a888425fd5 to your computer and use it in GitHub Desktop.
Save el-hoshino/52287f710b48d3890a3151a888425fd5 to your computer and use it in GitHub Desktop.
AssociativeComparison
precedencegroup AssociativeComparisonPrecedence {
associativity: left
higherThan: ComparisonPrecedence
lowerThan: NilCoalescingPrecedence
}
infix operator <: AssociativeComparisonPrecedence
infix operator <=: AssociativeComparisonPrecedence
public func < <V: Comparable>(lhs: V, rhs: V) -> (Bool, V) {
return ((lhs < rhs), rhs)
}
public func <= <V: Comparable>(lhs: V, rhs: V) -> (Bool, V) {
return ((lhs <= rhs), rhs)
}
public func < <V: Comparable>(lhs: (Bool, V), rhs: V) -> (Bool, V) {
return ((lhs.0 && lhs.1 < rhs), rhs)
}
public func <= <V: Comparable>(lhs: (Bool, V), rhs: V) -> (Bool, V) {
return ((lhs.0 && lhs.1 <= rhs), rhs)
}
public func < <V: Comparable>(lhs: (Bool, V), rhs: V) -> Bool {
return lhs.0 && (lhs.1 < rhs)
}
public func <= <V: Comparable>(lhs: (Bool, V), rhs: V) -> Bool {
return lhs.0 && (lhs.1 <= rhs)
}
let a = 2
let b = 3
if 1 < a < b <= 3 {
print("true") // true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment