Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created March 26, 2015 23: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 JadenGeller/d3e179ca03f63036cb3e to your computer and use it in GitHub Desktop.
Save JadenGeller/d3e179ca03f63036cb3e to your computer and use it in GitHub Desktop.
Swift Goes Toward
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