Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
Created July 25, 2014 08:52
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 seanlilmateus/b40298896be3a66c7148 to your computer and use it in GitHub Desktop.
Save seanlilmateus/b40298896be3a66c7148 to your computer and use it in GitHub Desktop.
I created my own Range literals that make more sense than N..<M in Swift, inspired by Gosu
operator infix |⋅⋅ {}
@infix func |⋅⋅ (lhs: Int, rhs: Int) -> Range<Int> {
return Range(start: lhs + 1, end: rhs)
}
operator infix |⋅⋅| {}
@infix func |⋅⋅|(lhs: Int, rhs: Int) -> Range<Int> {
return Range(start: lhs+1, end: rhs-1)
}
operator infix ⋅⋅| {}
@infix func ⋅⋅| (lhs: Int, rhs: Int) -> Range<Int> {
return Range(start: lhs, end: rhs-1)
}
let range0 = 0|⋅⋅20
println("Range \(range0)")
let range1 = 0⋅⋅|20
println("Range \(range1)")
let range2 = 0|⋅⋅|20
println("Range \(range2)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment