1
struct EnumerableDrop{T,S} <: Enumerable
2 23
    source::S
3
    n::Int
4
end
5

6
function drop(source::Enumerable, n::Integer)
7 23
    T = eltype(source)
8
    S = typeof(source)
9 23
    return EnumerableDrop{T,S}(source, Int(n))
10
end
11

12 0
Base.IteratorSize(::Type{EnumerableDrop{T,S}}) where {T,S} = (Base.IteratorSize(S) isa Base.HasLength || Base.IteratorSize(S) isa Base.HasShape) ? Base.HasLength() : Base.SizeUnknown()
13

14 0
Base.eltype(::Type{EnumerableDrop{T,S}}) where {T,S} = T
15

16 5
Base.length(iter::EnumerableDrop{T,S}) where {T,S} = max(length(iter.source)-iter.n,0)
17

18
function Base.iterate(iter::EnumerableDrop{T,S}) where {T,S}
19 23
    ret = iterate(iter.source)
20 23
    for i in 1:iter.n
21 23
        if ret===nothing
22 23
            return nothing
23
        else
24 23
            ret = iterate(iter.source, ret[2])
25
        end
26
    end
27 23
    return ret
28
end
29

30
function Base.iterate(iter::EnumerableDrop{T,S}, state) where {T,S}
31 23
    return iterate(iter.source, state)
32
end

Read our documentation on viewing source code .

Loading