Skip to content
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

Unexpected interaction of Pull.bracketCase and Stream's flatMap #3118

Open
buzden opened this issue Jan 29, 2023 · 0 comments
Open

Unexpected interaction of Pull.bracketCase and Stream's flatMap #3118

buzden opened this issue Jan 29, 2023 · 0 comments
Labels

Comments

@buzden
Copy link

buzden commented Jan 29, 2023

Context

The fact that Stream[F, O] can be easily got from Pull[F, O, Unit] is severely used in this example.

Stream's bracket API does not allow the release action to emit output values, since it takes F[...], not Stream[F, ...]. But, Pull's bracket API does allow to emit values, since it takes Pull[F, O, Unit] as a release action.

Possibly unexpected situation

Consider now a situation when I have some effect after some emit in the release action of some bracket of some Pull. Now consider that I converted this to a Stream and flatMap'ed on it and in the RHS side of this flatMap an error occurs. You can see illustrating code for this. Do you expect an effect in the release action, which goes after the emit to occur? I did, at least at first, but actually, at least on v3.5.0 release action do not finish all its actions.

Later I realised that maybe this can be thought of as expected semantics since flatMap'ing on Streams actually means that we kinda insert intermediate actions instead of emits of a stream on LHS, so it this action fails, the whole stream fails no matter it is a release function. Kind of, you must watch (and maybe guard) your emits in the release action, if you have one.

Despite that, I had a little discussion with other developers who agreed that despite this explanation, they would expect all effects in the release action to be executed because of pragmatics of it.

Definitely unexpected situation

Okay, let's guard the final effectful action which should go after emit in the release action. To do this, let's make another bracket. You can see example of this change here. But, this bracket in the release action simply does not work as a bracket, and this is completely unexpected.

@buzden buzden added the bug label Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant