From 550d04df69ff13b0f8a7fe8f181cbe833e5ff3bf Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Fri, 5 Nov 2021 14:15:01 +0100 Subject: [PATCH 1/2] Add missing type parameter to TakeWhile I can't say I really understand what difference it makes, but without this `TakeWhile` has `eltype` of `Any` --- base/iterators.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/iterators.jl b/base/iterators.jl index c76f8b8d4c3a0..48f9017fddce5 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -790,7 +790,7 @@ end IteratorSize(::Type{<:TakeWhile}) = SizeUnknown() eltype(::Type{TakeWhile{I,P}} where P) where {I} = eltype(I) -IteratorEltype(::Type{TakeWhile{I}} where P) where {I} = IteratorEltype(I) +IteratorEltype(::Type{TakeWhile{I, P}} where P) where {I} = IteratorEltype(I) # dropwhile From ef690a8bec1303048b574789c0e4886ed20c9a50 Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Fri, 5 Nov 2021 18:07:15 +0100 Subject: [PATCH 2/2] add test for eltype of takewhile and dropwhile --- test/iterators.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/iterators.jl b/test/iterators.jl index b16b75291c270..8de847018255d 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -212,6 +212,7 @@ end @test collect(takewhile(Returns(true),5:10)) == 5:10 @test collect(takewhile(isodd,[1,1,2,3])) == [1,1] @test collect(takewhile(<(2), takewhile(<(3), [1,1,2,3]))) == [1,1] + @test Base.IteratorEltype(typeof(takewhile(<(4),Iterators.map(identity, 1:10)))) isa Base.EltypeUnknown end # dropwhile @@ -224,6 +225,7 @@ end @test isempty(dropwhile(Returns(true), 1:3)) @test collect(dropwhile(isodd,[1,1,2,3])) == [2,3] @test collect(dropwhile(iseven,dropwhile(isodd,[1,1,2,3]))) == [3] + @test Base.IteratorEltype(typeof(dropwhile(<(4),Iterators.map(identity, 1:10)))) isa Base.EltypeUnknown end # cycle