Skip to content

merge: Ability to identify source of an "event" #137

@madduck

Description

@madduck

When I merge two streams like so:

sources = aiostream.stream.merge(genstrings1, genlists2)
with sources.stream() as events_gen:
    for event in events_gen:
        ...  # Does event come from gen1 or gen2?

then I have to test the data to determine which of the source generators this event — I hope it's okay I refer to the data as events — was taken from. This is not always possible. For instance, if I have two sources generating strings, there is no sure way to discern which source stream generated a given string.

Would you consider something like this in addition?

sources = aiostream.stream.mergetuple(gen1, gen2)
with sources.stream() as events_gen:
    for gen, event in events_gen:
        if gen == gen1:
            # event comes from gen1
        elif gen == gen2:
            # event comes from gen2

Or is there another way?

I am currently using ziplatest and keeping track of each object so that I can identify which of the items in the zip actually changed vs. the last iteration. This is quite ugly, I find.

Looking forward to ideas, or a sign that you'd be open to a PR…

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions