Skip to content

Commit

Permalink
Add missing type parameter to TakeWhile (JuliaLang#42958)
Browse files Browse the repository at this point in the history
Without this `TakeWhile` has `eltype` of `Any`
  • Loading branch information
pepijndevos authored Nov 9, 2021
1 parent 0771250 commit ab0c6dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ab0c6dd

Please sign in to comment.