Skip to content

Instantly share code, notes, and snippets.

@Nadohs
Created August 25, 2015 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nadohs/30f4ec3cb9806223b6f4 to your computer and use it in GitHub Desktop.
Save Nadohs/30f4ec3cb9806223b6f4 to your computer and use it in GitHub Desktop.
range comparing...
<>, both not included in range,
<=>, both included
<==, left not included,
==> right not included
infix operator <> {}
infix operator <=> {}
infix operator ==> {}
infix operator <== {}
func <=> <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{
if lhs < rhs.0{
return false
}
if lhs > rhs.1{
return false
}
return true
}
func <> <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{
if lhs <= rhs.0{
return false
}
if lhs >= rhs.1{
return false
}
return true
}
func ==> <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{
if lhs < rhs.0{
return false
}
if lhs >= rhs.1{
return false
}
return true
}
func <== <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{
if lhs <= rhs.0{
return false
}
if lhs > rhs.1{
return false
}
return true
}
let x = 5
let res = 5 <> (3, 5)
let res1 = 5 <=> (3, 5)
let res1b = 5 ==> (3, 5)
let res1c = 5 <== (3, 5)
let res2 = 5 <> (5, 7)
let res3 = 5 <=> (5, 7)
let res3b = 5 ==> (5, 7)
let res3c = 5 <== (5, 7)
@stretch07
Copy link

least recently edited gist lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment