[RFC/ANN] FLoops.jl: fast generic for loops (foldl for humans™)

It turned out deriving iterate from Python-like syntax is super easy since IRTools.jl already has the CPS conversion. See https://github.com/tkf/GeneratorsX.jl 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.

7 Likes

Related work regarding python style generators: https://github.com/BenLauwens/ResumableFunctions.jl and PyGen - python style generators.

Good point. The implementation of ResumableFunctions.jl is based on mutation so it’s not the best choice for performance (especially for type-changing state) and parallelism. PyGen seems to be using a Channel so that’s not good for performance and parallelism either.

5 Likes