Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,15 @@ filter(flt, itr) = Filter(flt, itr)
function iterate(f::Filter, state...)
y = iterate(f.itr, state...)
while y !== nothing
if f.flt(y[1])
return y
v, s = y
if f.flt(v)
if y isa Tuple{Any,Any}
return (v, s) # incorporate type information that may be improved by user-provided `f.flt`
else
return y
end
end
y = iterate(f.itr, y[2])
y = iterate(f.itr, s)
end
nothing
end
Expand Down
5 changes: 5 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1201,3 +1201,8 @@ end
@testset "Iterators docstrings" begin
@test isempty(Docs.undocumented_names(Iterators))
end

# Filtered list comprehension (`Filter` construct) type inference
@test Base.infer_return_type((Vector{Any},)) do xs
[x for x in xs if x isa Int]
end == Vector{Int}