Created
July 25, 2014 08:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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