Skip to content

Instantly share code, notes, and snippets.

@Shehryar
Created December 2, 2019 18:13
Show Gist options
  • Save Shehryar/e90516ca26d3a7ab925118a0b8697a70 to your computer and use it in GitHub Desktop.
Save Shehryar/e90516ca26d3a7ab925118a0b8697a70 to your computer and use it in GitHub Desktop.
Custom operator for creating a closed countable range from two Characters
infix operator ←→
extension Character {
static func ←→(lhs: Character, rhs: Character) -> CountableClosedRange<UInt8> {
guard let lhsInt = lhs.asciiValue, let rhsInt = rhs.asciiValue else {
return 0...0
}
return lhsInt...rhsInt
}
}
}
let range = "A"←→"Z"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment