-
-
Notifications
You must be signed in to change notification settings - Fork 417
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
Syntactic sugar: Tree.has_data() #1465
Comments
I can suggest has_data = bool(next(tree.find_data(data), False)) |
Another option is: for _ in tree.find_data(data):
# do if true
break I understand having a method would be a bit more ergonomic, but I feel like it's a bit too small to be worth adding. But I'll leave it open, if more users would like this method, we can add it in. |
Thank you, this one is pretty close. I've forgotten about the However, it will not work when |
Yeah. Honestly, I don't know why itertools doesn't have this method: EMPTY = object()
def iter_is_empty(i) -> bool:
return next(i, EMPTY) is EMPTY |
It seems that people will tend to choose readability over performance: has_data = bool(tuple(tree.find_data(data))) (at least I will) |
Suggestion
Add new method
Tree.has_data(data: str) -> bool
to determine whether there is a token with given data.Describe alternatives you've considered
This can be achieved with
find_data()
method, but is too verbose:compared to
Additional context
I'm ready to provide PR if you find this API enhancement reasonable.
The text was updated successfully, but these errors were encountered: