1
# T is the type of the elements produced by this iterator
2
struct EnumerableFilter{T,S,Q<:Function} <: Enumerable
3 47
    source::S
4
    filter::Q
5
end
6

7 0
Base.eltype(iter::Type{EnumerableFilter{T,S,Q}}) where {T,S,Q} = T
8

9
function filter(source::Enumerable, filter_func::Function, filter_expr::Expr)
10 47
    T = eltype(source)
11
    S = typeof(source)
12 47
    Q = typeof(filter_func)
13 47
    return EnumerableFilter{T,S,Q}(source, filter_func)
14
end
15

16
function Base.iterate(iter::EnumerableFilter{T,S,Q}, state...) where {T,S,Q}
17 47
    ret = iterate(iter.source, state...)
18

19 47
    while ret!==nothing
20 47
        if iter.filter(ret[1])
21 47
            return ret
22
        end
23

24 47
        ret = iterate(iter.source, ret[2])
25
    end
26

27 47
    return nothing
28
end

Read our documentation on viewing source code .

Loading