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

Allow adapted feeds to filter messages #123

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

mhidalgo-bdai
Copy link
Contributor

This patch adds a simple, generic mechanism for AdaptedFeed instances to drop messages.

TypeVar,
Union,
overload,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

black decided it was time to reformat 🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a line length limit for black.

"""
super().__init__()
self.fn = fn
self.connection = upstream.registerCallback(self.add)

def add(self, *messages: Any) -> None:
"""Adds new `messages` to the adapter."""
self.signalMessage(self.fn(*messages))
result = self.fn(*messages)
Copy link
Contributor Author

@mhidalgo-bdai mhidalgo-bdai Oct 2, 2024

Choose a reason for hiding this comment

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

@amessing-bdai ended up going with the trivial implementation. There is a way, an async way, for fn to nicely embed complex, stateful logic in a functional way, but it was more trouble than it was worth. If one needs lots of bookkeeping and control flow for an adapter, it may be about time to write a new filter.

@mhidalgo-bdai mhidalgo-bdai merged commit 6ed50d7 into main Oct 2, 2024
3 checks passed
@mhidalgo-bdai mhidalgo-bdai deleted the mhidalgo-bdai/adapters-are-filters branch October 2, 2024 17:53
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