Skip to content

Instantly share code, notes, and snippets.

@nadar71
Created May 11, 2022 14:43
Show Gist options
  • Save nadar71/d209443a5760267802557ab96904e9b1 to your computer and use it in GitHub Desktop.
Save nadar71/d209443a5760267802557ab96904e9b1 to your computer and use it in GitHub Desktop.
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