Accept a function to determine how to save the previous message in WithPrevious
#344
Labels
part:experimental
Affects the experimental package
type:enhancement
New feature or enhancement visitble to users
Milestone
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.
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
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]
.The text was updated successfully, but these errors were encountered: