Skip to content

Instantly share code, notes, and snippets.

@calvinlfer
Created September 21, 2024 23:26
Show Gist options
  • Save calvinlfer/2ef382c3fbea1620abd6f1108a9e6349 to your computer and use it in GitHub Desktop.
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)
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