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

**URL:** <https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876>\
**Category:** Package Announcements\
**Created:** [April 20, 2020, 4:05am UTC](https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876 "2020-04-20T04:05:51Z")\
**Posts on this page:** 3\
**Page:** 3

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 29, 2020, 4:04am UTC](https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876/41 "2020-04-29T04:04:28Z")

</div>

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™](https://github.com/tkf/GeneratorsX.jl) for a POC (requires Julia 1.5-DEV):

```julia
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:

> <https://github.com/JuliaFolds/GeneratorsX.jl/blob/ee29e0eeaf71cf8f55d384462683fe74fc818008/test/test_samples.jl#L21-L27>

Note that when executing via FLoops.jl, there is no need for IRTools.jl and the code you write would be executed as-is.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [April 29, 2020, 11:52am UTC](https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876/42 "2020-04-29T11:52:13Z")

</div>

Related work regarding python style generators: [https://github.com/BenLauwens/ResumableFunctions.jl](https://github.com/BenLauwens/ResumableFunctions.jl) and [PyGen - python style generators](https://discourse.julialang.org/t/pygen-python-style-generators/3451).

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 29, 2020, 6:29pm UTC](https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876/43 "2020-04-29T18:29:12Z")

</div>

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.

[Previous page](https://discourse.julialang.org/t/rfc-ann-floops-jl-fast-generic-for-loops-foldl-for-humans/37876.md?page=2)
