Automate allocation

If you do not mind a new struct type:

struct OnRepeat{F}
    f :: F
end

function Base.iterate(o :: OnRepeat{F}, s :: Nothing = nothing) where {F}
    return o.f(), nothing
end

a, b, c = OnRepeat(() -> [])

And now you can use OnRepeat with any function taking no arguments and returning the new object you want.

7 Likes