Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions base/iterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

isempty(itr) = done(itr, start(itr))


# enumerate

immutable Enumerate{I}
Expand Down Expand Up @@ -210,3 +211,15 @@ next(it::Repeated, state) = (it.x, nothing)
done(it::Repeated, state) = false

repeated(x, n::Int) = take(repeated(x), n)

# Infinite-length Iterators

typealias InfiniteIterator Union{Cycle,Repeated,Count} # TODO: we should do this with traits once we have #13222

# Zips with infinite-length components

length{I<:InfiniteIterator,Z<:AbstractZipIterator}(z::Zip{I,Z}) = length(z.z)
length{I1<:InfiniteIterator,I2<:InfiniteIterator}(z::Zip2{I1,I2}) = length(z.b) # inherit behaviour, error
length{I1,I2<:InfiniteIterator}(z::Zip2{I1,I2}) = length(z.a)
length{I1<:InfiniteIterator,I2}(z::Zip2{I1,I2}) = length(z.b)

3 changes: 3 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ let i = 0
end
end

@test length(zip(cycle(1:3), 1:7)) == 7
@test length(zip(cycle(1:3), 1:7, cycle(1:3))) == 7

# repeated
# --------

Expand Down