Created
September 21, 2024 23:26
-
-
Save calvinlfer/2ef382c3fbea1620abd6f1108a9e6349 to your computer and use it in GitHub Desktop.
Modelling lazy infinite streams in Kyo 0.12.x (https://getkyo.io/#/?id=stream-composable-data-processing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kyo.* | |
import kyo.Emit.Ack | |
object Playground extends KyoApp: | |
def recursiveStream(start: Int): Stream[Int, IO] = | |
def go(n: Int): Ack < Emit[Chunk[Int]] = | |
Emit.andMap(Chunk(n)): | |
case Ack.Stop => Ack.Stop | |
case Ack.Continue(_) => go(n + 1) | |
Stream(go(start)) | |
run: | |
val computation = recursiveStream(1).take(32).run | |
for | |
c <- computation | |
_ <- IO(println(c)) | |
yield () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment