-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
length
method for iterables
#13772
Comments
The iterator protocol does not guarantee at this moment/to my knowledge that the elements and the length of the iterator does not change when julia iterates over the iterator again. So calling |
@mschauer What do you mean by "there cannot be a general fallback counting the elements and giving useful information."? Here is a general fallback counting the elements and giving useful information.
The following shows that it returns useful information.
There are plenty of functions on iterators that do not rely on a |
I think it would be pretty unpleasant to call It seems better that those functions that could deal with iterables without a |
@my-little-repository You can check your intuition against the following iterator:
Defining
|
@toivoh At the moment,
So you suggest rewriting it so it works even if |
I agree with @mschauer. A default The general problem with iterators like |
Shouldn't there be a default
length
method based on start/next/done? At the moment,collect
fails on iterables which do not have a length method.Arguably, this means that
collect
may hang ifdone
never returns a true value. But there are many functions that exhibit such a behavior at the moment, so this does not really worsen the matter.The text was updated successfully, but these errors were encountered: