Created
June 14, 2017 11:55
-
-
Save fgoinai/b4c430706e8664d8eea61e3b6712e7d2 to your computer and use it in GitHub Desktop.
Fib generator using kotlin coroutine
This file contains hidden or 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
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