1
struct EnumerableMap{T, S, Q<:Function} <: Enumerable
2 23
    source::S
3
    f::Q
4
end
5

6 0
Base.IteratorSize(::Type{EnumerableMap{T,S,Q}}) where {T,S,Q} = haslength(S)
7

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

10 5
Base.length(iter::EnumerableMap{T,S,Q}) where {T,S,Q} = length(iter.source)
11

12
function map(source::Enumerable, f::Function, f_expr::Expr)
13 23
    TS = eltype(source)
14 23
    T = Base._return_type(f, Tuple{TS,})
15
    S = typeof(source)
16 23
    Q = typeof(f)
17 23
    return EnumerableMap{T,S,Q}(source, f)
18
end
19

20
function Base.iterate(iter::EnumerableMap{T,S,Q}, state...) where {T,S,Q}
21 5
    ret = iterate(iter.source, state...)
22 10
    if ret===nothing
23 10
        return nothing
24
    else
25 10
        return iter.f(ret[1]), ret[2]
26
    end
27
end

Read our documentation on viewing source code .

Loading