8000 [data][prelude][core] Poll effect + handleFirst by fwbrasil · Pull Request #891 · getkyo/kyo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[data][prelude][core] Poll effect + handleFirst #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2024
Merged

[data][prelude][core] Poll effect + handleFirst #891

merged 4 commits into from
Dec 5, 2024

Conversation

fwbrasil
Copy link
Collaborator
@fwbrasil fwbrasil commented Dec 3, 2024

Introduces a new Poll effect that functions as the opposite of Emit. I've also introduced ArrowEffect.handleFirst and Emit.handleFirst, which might be useful for the work on Stream. I'm planning to use Poll for an Actor implementation.

@@ -0,0 +1,66 @@
package kyo
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,oved to the kyo package since it's shared between Emit, Poll, and Stream.

@fwbrasil fwbrasil mentioned this pull request Dec 4, 2024
8000 Copy link
Collaborator
@hearnadam hearnadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool effect! Will need to dive deeper to see how I can make use of it.

end apply
end RunFirstOps

inline def runFirst[V >: Nothing]: RunFirstOps[V] = RunFirstOps(())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runHead?

Copy link
Collaborator Author
@fwbrasil fwbrasil Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep a consistent naming with ArrowEffect.handleFirst. The "first" is more about the first suspension than the first element.

* A computation that processes values until completion
*/
def apply[S](f: V => Unit < S)(using tag: Tag[Poll[V]], frame: Frame): Unit < (Poll[V] & S) =
Loop(()) { _ =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a apply0? Followup is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried some time ago but had inference issues

ArrowEffect.handleFirst(emitTag, emit)(
handle = [C] =>
(emitted, emitCont) =>
// Debug.values(emitted)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

ArrowEffect.handleFirst(pollTag, poll)(
handle = [C2] =>
(ack, pollCont) =>
// Debug.values(ack)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

// 2. Pass the emitted value to poller for consumption
// 3. Recursively continue the cycle
Loop.continue(emitCont(ack), pollCont(Maybe(emitted))),
8000 // Poll.run(emitCont(ack))(pollCont(Maybe(emitted))),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

Loop.continue(emitCont(ack), pollCont(Maybe(emitted))),
// Poll.run(emitCont(ack))(pollCont(Maybe(emitted))),
done = b =>
// Debug.values(b)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

* @return
* The transformed computation result
*/
inline def handleFirst[I[_], O[_], E <: ArrowEffect[I, O], A, B, S, S2](effectTag: Tag[E], v: A < (E & S))(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect handling is starting to get interesting!

Emit.runDiscard(emitCont(Ack.Stop)).map(a => Loop.done((a, b)))
),
done = a =>
// Debug.values(a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

fwbrasil and others added 2 commits December 5, 2024 08:37
Co-authored-by: Adam Hearn <22334119+hearnadam@users.noreply.github.com>
@fwbrasil fwbrasil merged commit 7baf292 into main Dec 5, 2024
2 of 3 checks passed
@fwbrasil fwbrasil deleted the pull branch December 5, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0