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

Accept a function to determine how to save the previous message in WithPrevious #344

Open
llucax opened this issue Nov 29, 2024 · 0 comments
Labels
part:experimental Affects the experimental package type:enhancement New feature or enhancement visitble to users
Milestone

Comments

@llucax
Copy link
Contributor

llucax commented Nov 29, 2024

What's needed?

WithPrevious is still a bit limited as how the previous message is saved is hardcoded (it only saves the new message unconditionally).

Proposed solution

Accept an extra argument with a function to determine what to save as the last message instead of always saving the new message.

def __init__(self, ..., get_previous: Callable[[T, T], T], ...):

Where the first argument is the previous message, the second argument is the new message and the return is what's saved as the previous message.

Use cases

  • Implement a filter that ensures the received messages are monotonically increasing: get_previous=lambda prev, new: max(prev, new).

Alternatives and workarounds

Write a custom filter predicate from scratch.

Additional context

This would make the API a bit more complicated as we actually need to expose the sentinel, because the previous message could be not received yet, or make the feature less flexible and always saving the first message as the previous message.

With a sentinel it would look like Callable[[T | MISSING, T], T].

@llucax llucax added part:experimental Affects the experimental package type:enhancement New feature or enhancement visitble to users labels Nov 29, 2024
@llucax llucax added this to the Untriaged milestone Nov 29, 2024
@llucax llucax changed the title Accept a function to determine how to save the previous message in OnlyIfPrevious Accept a function to determine how to save the previous message in WithPrevious Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:experimental Affects the experimental package type:enhancement New feature or enhancement visitble to users
Projects
None yet
Development

No branches or pull requests

1 participant