Skip to content

Instantly share code, notes, and snippets.

@russbishop
Last active October 28, 2016 18:20
Show Gist options
  • Save russbishop/eff38139b936043fba343332add5ae70 to your computer and use it in GitHub Desktop.
Save russbishop/eff38139b936043fba343332add5ae70 to your computer and use it in GitHub Desktop.
OptionalCompare.swift
func < <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
}
func > <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l > r
default:
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment