-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add take_while
and drop_while
to Receiver
#356
Conversation
The `take_while()` method is just an alias for `filter()`, with the intention to eliminate the ambiguity and make it more readable. On the other hand, `drop_while()` is the negation of `take_while()` and provided as a convenience and also to improve readability. These names are widely popular and used in other programming languages as well as the Python `itertools` module. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
There is no need to test the methods that are implemented in `Receiver` itself for every channel or receiver implementation. We also add a couple of extra trivial tests. Signed-off-by: Leandro Lucarella <[email protected]>
I didn't take a lot of time to think if |
I haven't looked at the code yet, but I'd imagine |
I think we can bump minor versions, we didn't discuss in depth policies about updates, but I would consider requiring updating dependencies, if they are backwards compatible, not a breaking change. For me a breaking change is something that forces you to update the code, not the tooling. |
I just looked at As far as I can see, we would need to declare def drop_while(
self,
filter_function: Callable[[ReceiverMessageT_co], TypeIs[FilteredMessageT_co]
],
/,
) -> Receiver[ReceiverMessageT_co & ^FilteredMessageT_co]: There seems to be some progress in adding intersection to Python and negation, but I'm not sure how feasible that would be, at least judging from the what the typing docs says about
Also from this comment from the maintainer of |
Oh, dammit, I just realized we misinterpreted what
>>> print(list(takewhile(lambda x: x < 4, [1, 2, 3, 4, 5, 6])))
[1, 2, 3]
>>> print(list(dropwhile(lambda x: x < 4, [1, 2, 3, 4, 3, 2, 1])))
[4, 3, 2, 1] So we need new names, or forget about it / add I will close this PR and move the discussion back to the issue. |
The
take_while()
method is just an alias forfilter()
, with the intention to eliminate the ambiguity and make it more readable.On the other hand,
drop_while()
is the negation oftake_while()
and provided as a convenience and also to improve readability.These names are widely popular and used in other programming languages as well as the Python
itertools
module.Fixes #354.