Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Created July 15, 2014 03:18
Show Gist options
  • Save kongtomorrow/f6caf36c6b6e3bd34a36 to your computer and use it in GitHub Desktop.
Save kongtomorrow/f6caf36c6b6e3bd34a36 to your computer and use it in GitHub Desktop.
generators
func triangleNums(count:Int)->GeneratorOf<Int> {
var i = 0
return GeneratorOf<Int> {
++i < count ? (1+i)*i/2 : nil
}
}
for i in triangleNums(10) {
println(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment