Skip to content

Instantly share code, notes, and snippets.

@khanlou
Created November 16, 2016 04:14
Show Gist options
  • Select an option

  • Save khanlou/efac5bdf9ff6a0497b489817a7006972 to your computer and use it in GitHub Desktop.

Select an option

Save khanlou/efac5bdf9ff6a0497b489817a7006972 to your computer and use it in GitHub Desktop.
extension SignedInteger {
func times(_ each: () -> ()) {
var count: Self = 0
while (count < self) { each(); count = count + 1 }
}
}
extension SignedInteger {
func timesWithIndex(_ each: (Self) -> ()) {
var count: Self = 0
while (count < self) { each(count); count = count + 1 }
}
}
5.timesWithIndex { i in
print("hello", i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment