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

Avoid Dropping Upstream Items in mergeSource #513

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

julmb
Copy link
Contributor

@julmb julmb commented Aug 26, 2024

From what I understand, mergeSource will await an item from upstream, and if successful, await an item from src0. If there is no item in src0, the conduit terminates. This means that the item that was already taken from upstream is now lost (note the missing item 4 in the output):

>>> let num = C.yieldMany [1 .. 10]
>>> let chr = C.yieldMany ['a' .. 'c']
>>> runConduitPure $ num .| liftA2 (,) (mergeSource chr .| C.sinkList) C.sinkList
([('a',1),('b',2),('c',3)],[5,6,7,8,9,10])

This PR adds the already consumed item back using leftover, leading to the expected result:

([('a',1),('b',2),('c',3)],[4,5,6,7,8,9,10])

Disclaimer: I am pretty new to Conduit, so it is possible that I am either misunderstanding something or that there is a good reason for the current behavior of mergeSource, in which case, feel free to correct me.

Copy link
Owner

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

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

Seems like a good change. Can you add a comment to the changelog and do a minor version bump? An added test case would be great too, but not a blocker.

@julmb
Copy link
Contributor Author

julmb commented Aug 26, 2024

I added both a changelog entry and a test case.

Copy link
Owner

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

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

Thanks!

@snoyberg
Copy link
Owner

There's a build error in the tests due to missing the liftA2 import, can you address that?

@julmb
Copy link
Contributor Author

julmb commented Aug 26, 2024

I pushed right as you wrote that, let's hope it works now. ;)

@snoyberg snoyberg merged commit 1a04949 into snoyberg:master Aug 26, 2024
6 of 9 checks passed
@snoyberg
Copy link
Owner

LGTM, thanks!

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