-
Notifications
You must be signed in to change notification settings - Fork 1
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
Should it support non-iterable iterators? #16
Comments
Yes, this was intentional. The problem with accepting iterators is that it becomes this function's responsibility to close them, and the logic for that gets quite complicated especially when combined with the validating-up-front behavior. It's easy enough to wrap with |
I'm unsure that |
This also produces an iterator, like But yes, I agree this is somewhat strange. We decided to only accept real iterables because taking iterators invites a lot of complexity. For example, we decided we wanted to do eager validation, which means checking that all arguments are iterables up front (that would become "iterables or iterators"), but we don't want to open iterables until the result iterator actually reaches them so that we can avoid having to close them. So we'd have to store for each argument something like |
I agree about complexity of this. But... is this really required? For example, |
The general rule is that once someone hands you an iterator it is your responsibility to close it when you're done with it (unless it errors out or is exhausted). So iterators which haven't yet been returned by the |
This is not always observed. Let's take the first method that comes to hand - |
The iterator helper methods probably should close their receiver case of invalid arguments, actually, though the prototype methods are kind of special. Probably not too late to fix that. There's very few cases where we pass around an iterator - the |
It's not a similar case since here we already worked with this iterator ( |
Whether we have advanced this iterator or not is not a relevant distinction. |
It does for current precedents. All I see is that if we start working with the iterator, we close it. If we didn't start, no. |
There's barely anything which works with iterators at all, and the few places which do make that distinction do so only by accident, not as a considered choice which we need to carry forward. I'll try to get those fixed next meeting, but it's not something we are bound by either way. |
Iterators do not have to be iterable. However, with the current logic
will throw an error.
The namespace implies that the method should operate on iterators, not only iterables.
The text was updated successfully, but these errors were encountered: