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

Iteratorsize for partition iterator #16552

Merged
merged 2 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ mutable struct PartitionIterator{T}
end

eltype(::Type{PartitionIterator{T}}) where {T} = Vector{eltype(T)}
partition_iteratorsize(::HasShape) = HasLength()
partition_iteratorsize(isz) = isz
function iteratorsize(::Type{PartitionIterator{T}}) where {T}
partition_iteratorsize(iteratorsize(T))
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: you switched to the long-form function syntax because of the where syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


function length(itr::PartitionIterator)
l = length(itr.c)
Expand Down
7 changes: 7 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ let v = collect(partition([1,2,3,4,5], 1))
@test all(i->v[i][1] == i, v)
end

let v1 = collect(partition([1,2,3,4,5], 2)),
v2 = collect(partition(flatten([1,2,3,4,5]), 2))
@test v1[1] == v2[1] == [1,2]
@test v1[2] == v2[2] == [3,4]
@test v1[3] == v2[3] == [5]
end

let v = collect(partition([1,2,3,4,5], 2))
@test v[1] == [1,2]
@test v[2] == [3,4]
Expand Down