Created
March 26, 2015 23:52
-
-
Save JadenGeller/d3e179ca03f63036cb3e to your computer and use it in GitHub Desktop.
Swift Goes Toward
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
infix operator --> {associativity right precedence 90 assignment } | |
func --><T : IntegerType>(inout lhs: T, rhs: T) -> Bool { | |
if (lhs != rhs) { // Stride | |
lhs = lhs.advancedBy(rhs > lhs ? 1 : -1) | |
return true | |
} | |
else { | |
return false | |
} | |
} | |
// Examples | |
var x = 5 | |
while x --> 0 { | |
println(x) // -> 4 -> 3 -> 2 -> 1 -> 0 | |
} | |
var y = 2 | |
while y --> 7 { | |
println(y) // -> 3 -> 4 -> 5 -> 6 -> 7 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment