Skip to content

Instantly share code, notes, and snippets.

@siosio
Created September 22, 2014 08:22
Show Gist options
  • Save siosio/5348fc2bf0f2272f69ef to your computer and use it in GitHub Desktop.
Save siosio/5348fc2bf0f2272f69ef to your computer and use it in GitHub Desktop.
package fibo
fun fibo(max:Int):Stream<Pair<Int, Int>> {
return stream(Pair(0, 1)) {
val next = it.first + it.second
if (next < max) {
Pair(it.second, next)
} else {
null
}
}
}
fun main(args:Array<String>) {
fibo(10000).forEach {print("${it.first} ")}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment