A kotlin script producing a fibunacci range inspired by clovisai's contribution to kotlin discussion: Project Loom will make coroutines obsolete.
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())
(suggested file name: kotlin-script-fibonacci.kts)
kotlinc kotlin-script-fibonacci.kts -script -language-version 1.8 -include-runtime
Caution: kotlin custom scripting is experimental as of 1.7.20 (20221023).