It turned out deriving iterate
from Python-like syntax is super easy since IRTools.jl already has the CPS conversion. See GitHub - JuliaFolds/GeneratorsX.jl: iterate and foldl for humans™ for a POC (requires Julia 1.5-DEV):
julia> using GeneratorsX
julia> @generator function generate123()
@yield 1
@yield 2
@yield 3
end;
julia> collect(generate123())
3-element Array{Int64,1}:
1
2
3
It’s nice that something hairy like flatten
is very straight-forward to write:
Note that when executing via FLoops.jl, there is no need for IRTools.jl and the code you write would be executed as-is.