-
-
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
fix length for zips with cycles #13276
Conversation
An alternative to doing it this way is to define the length of Cycle and Repeated to be infinite:
This would generalize but may be controversial (as length is otherwise an Int). |
[edit: moved the argument over to #11977] |
See also discussion in #11977 |
Sorry, @simonbyrne , there was no intention to pre-empt the introduction of Alephs into julia with this PR ;-) |
You could also define the length of an infinite iterable to be |
@stevengj My first reaction is that this would be not a good idea. Producing an error when asking for the length of an infinite object is the current convention. That also sounds really prone to produce overflow when doing innocent computations like |
#11977 is closed, can we go ahead here? |
|
||
# Zips with infinite length components | ||
|
||
length{I<:Union{Cycle,Repeated},Z<:AbstractZipIterator}(z::Zip{I,Z}) = length(z.z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How's about at the top we do
typealias InfiniteIterators Union{Cycle,Repeated}
and add a TODO that we should do this with traits once we have #13222.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good suggestion.
Can be done in a much nicer way with the new Iterator traits. |
This fixes a small issue with Zips containing infinite components which prevented constructions like