Created
May 11, 2022 14:43
-
-
Save nadar71/d209443a5760267802557ab96904e9b1 to your computer and use it in GitHub Desktop.
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
suspend fun fibonacci(): Flow<BigInteger> = flow { | |
var x = BigInteger.ZERO | |
var y = BigInteger.ONE | |
while (true) { | |
emit(x) | |
x = y.also { | |
y += x | |
} | |
} | |
} | |
runBlocking { | |
launch{ | |
fibonacci().take(100).collect{ println(it) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment