Skip to content

Commit

Permalink
iteratorsize for partition iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer committed May 24, 2016
1 parent dcde84d commit 0b03386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions base/iterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ type PartitionIterator{T}
end

eltype{T}(::Type{PartitionIterator{T}}) = Vector{eltype(T)}
partition_iteratorsize(::HasShape) = HasLength()
partition_iteratorsize{T}(isz::T) = isz
iteratorsize{T}(P::Type{PartitionIterator{T}}) = partition_iteratorsize(iteratorsize(T))

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

let v = collect(Base.partition([1,2,3,4,5], 2))
@test v[1] == [1,2]
@test v[2] == [3,4]
@test v[3] == [5]
let v1 = collect(Base.partition([1,2,3,4,5], 2)), v2 = collect(Base.partition(Base.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(Base.partition(enumerate([1,2,3,4,5]), 3))
Expand Down

0 comments on commit 0b03386

Please sign in to comment.