From ab0c6dd56752c1860fa8d97471f0eafaac671a85 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` --- 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 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 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