A question about ArrowEffect#handle and introducing new effects #1391
-
|
Hello all, I am slowly reading through the Kyo source code. I'm trying to fully understand the project because it sparked my interest. I came across
I am a bit confused about the claim that no new effects may be introduced during the handling process, because the Is this me misunderstanding how this function works? If so, could some give me a hint as to why this does not allow introducing new effects? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
@fwbrasil can you answer this? It does look like you can introduce new effects. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the ping @johnhungerford! Yes, the scaladoc is incorrect. A good example is def filter[VV >: V, S2](f: VV => Boolean < S2)(using tag: Tag[Emit[Chunk[VV]]], frame: Frame): Stream[VV, S & S2] =
Stream(
ArrowEffect.handleLoop(tag, emit)(
[C] =>
(input, cont) =>
Kyo.filter(input)(f).map { c =>
if c.isEmpty then Loop.continue(cont(()))
else Emit.valueWith(c)(Loop.continue(cont(())))
}
)
)Note how it's possible to first re-emit the current As a side note, in Kyo we use a naming pattern where methods with the @toonvanacker would you mind creating an issue or PR for this? Thank you for the question 🙏 |
Beta Was this translation helpful? Give feedback.
Thank you for the ping @johnhungerford!
Yes, the scaladoc is incorrect.
handledoes allow introducing new effects but it has an important restriction: it's not possible to introduce new suspensions of the same effect that is being handled. Given that it recurses until all suspensions of the effect are handled, it'll just recurse indefinitely in case the handling introduces a suspension of the same effect.handleis enough for the majority of the effects but there are cases where it's necessary to suspend the same effect again.A good example is
stream.filter. It handles the stream and needs to emit elements of the same type again if they pass the filter: