Skip to content

Instantly share code, notes, and snippets.

@fgoinai
Created June 14, 2017 11:55
Show Gist options
  • Save fgoinai/b4c430706e8664d8eea61e3b6712e7d2 to your computer and use it in GitHub Desktop.
Save fgoinai/b4c430706e8664d8eea61e3b6712e7d2 to your computer and use it in GitHub Desktop.
Fib generator using kotlin coroutine
fun main(args: Array<String>) {
fib.take(10).forEach { println(it) }
}
val fib = buildSequence {
var tmp = Pair(0, 1)
while(true) {
yield(tmp.first)
tmp = Pair(tmp.second, tmp.first + tmp.second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment