From 7617229a6353108abc5084d75b7c683bcd0f01ad Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Tue, 9 Nov 2021 19:41:54 +0100 Subject: [PATCH] Add missing type parameter to TakeWhile (#42958) Without this `TakeWhile` has `eltype` of `Any` (cherry picked from commit ab0c6dd56752c1860fa8d97471f0eafaac671a85) --- base/iterators.jl | 2 +- test/iterators.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/base/iterators.jl b/base/iterators.jl index f9728cbbd0793..64e661bf4be0c 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -786,7 +786,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 diff --git a/test/iterators.jl b/test/iterators.jl index 86c325a85b617..fb6f213fae80d 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -202,6 +202,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 @@ -214,6 +215,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