A kotlin custom script producing a fibunacci range inspired by clovisai’s contribution to kotlin discussion: Project Loom will make coroutines obsolete.
run script
val fibonacci = sequence {
yield(1)
var cur = 1
var next = 1
while (true) {
yield(next)
val tmp = cur + next
cur = next
next = tmp
}
}
println(fibonacci.take(15).joinToString())
kotlinc kotlin-script-fibonacci.kts -script \ -language-version 1.8 -include-runtime
Caution: kotlin custom scripting is experimental as of Kotlin 1.7.20 (20221023).
See also: https://gist.github.com/lotharschulz/79d3641c73f7b28120d1205ceef877fe
Originally published at https://www.lotharschulz.info.