A MWE:
struct MyIter
n
limit
end
function Base.iterate(m::MyIter)
state = ones(m.n)
return (state,state .+ 1)
end
function Base.iterate(m::MyIter,state)
if first(state) > m.limit
return nothing
else
new_state = state .+ 1
return (state,new_state)
end
end
function Base.length(m::MyIter)
return m.limit
end
collect(MyIter(2,10))
This will return:
julia> collect(MyIter(2,10))
10-element Vector{Any}:
[1.0, 1.0]
[2.0, 2.0]
[3.0, 3.0]
[4.0, 4.0]
[5.0, 5.0]
[6.0, 6.0]
[7.0, 7.0]
[8.0, 8.0]
[9.0, 9.0]
[10.0, 10.0]
Is there a different design such that my iterator could return [[1.0,2.0...,10.0],[1.0,2.0...,10.0]]
or an n
by limit
matrix, without users needing to do that step manually when collect
ing?