Simple Build with Yield
Shows that only the required elements are evaluated from the sequence.
GT-Sandbox-Snapshot
Code
package com.glassthought.sandbox
import kotlinx.coroutines.runBlocking
val seq = sequence {
println("Generating first")
yield(1)
println("Generating second")
yield(2)
println("Generating third")
yield(3)
println("Done")
}
fun main() = runBlocking {
println("Final output: " + seq.take(2).toList())
}
Command to reproduce:
gt.sandbox.checkout.commit f3e001677ad7af65443f \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew run --quiet"
Recorded output of command:
Generating first
Generating second
Final output: [1, 2]
Backlinks