Skip to content

Commit 6025150

Browse files
committed
iteratorsize for partition iterator
1 parent c463c1f commit 6025150

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

base/iterators.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ mutable struct PartitionIterator{T}
799799
end
800800

801801
eltype(::Type{PartitionIterator{T}}) where {T} = Vector{eltype(T)}
802+
partition_iteratorsize(::HasShape) = HasLength()
803+
partition_iteratorsize(isz) = isz
804+
function iteratorsize(::Type{PartitionIterator{T}}) where {T}
805+
partition_iteratorsize(iteratorsize(T))
806+
end
802807

803808
function length(itr::PartitionIterator)
804809
l = length(itr.c)

test/iterators.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ let v = collect(partition([1,2,3,4,5], 1))
356356
@test all(i->v[i][1] == i, v)
357357
end
358358

359+
let v1 = collect(partition([1,2,3,4,5], 2)),
360+
v2 = collect(partition(flatten([1,2,3,4,5]), 2))
361+
@test v1[1] == v2[1] == [1,2]
362+
@test v1[2] == v2[2] == [3,4]
363+
@test v1[3] == v2[3] == [5]
364+
end
365+
359366
let v = collect(partition([1,2,3,4,5], 2))
360367
@test v[1] == [1,2]
361368
@test v[2] == [3,4]

0 commit comments

Comments
 (0)