1
struct GeneratorWithElType{T, S}
2
    source::S
3
end
4

5
function IteratorInterfaceExtensions.getiterator(source::Base.Generator)
6 0
    TS = eltype(source.iter)
7 0
    T = Base.return_types(source.f, (TS,))[1]
8 0
    S = typeof(source)
9

10 0
    if isconcretetype(T)
11 0
        return GeneratorWithElType{T,S}(source)
12
    else
13 0
        return source
14
    end
15
end
16

17
function TableTraits.isiterabletable(source::Base.Generator)
18 0
    TS = eltype(source.iter)
19 0
    T = Base.return_types(source.f, (TS,))[1]
20

21 0
    if isconcretetype(T)
22 0
        if T <: NamedTuple
23 0
            return true
24
        else
25 0
            return false
26
        end
27
    else
28 0
        return missing
29
    end
30
end
31

32 0
Base.IteratorSize(::Type{GeneratorWithElType{T,S}}) where {T,S} = Base.IteratorSize(S)
33

34 0
Base.size(it::GeneratorWithElType, dims...) = size(it.source, dims...)
35

36 0
Base.length(it::GeneratorWithElType) = length(it.source)
37

38 0
Base.eltype(::Type{GeneratorWithElType{T,TS}}) where {T,TS} = T
39

40 0
Base.iterate(it::GeneratorWithElType) = iterate(it.source)
41

42 0
Base.iterate(it::GeneratorWithElType, state) = iterate(it.source, state)

Read our documentation on viewing source code .

Loading