Is there a macro for creating fast Iterators from generator-like functions in julia? : <p>Coming from python3 to Julia one would love to be able to write <strong>fast</strong> iterators as a function with produce/yield syntax or something like that.</p>

<p>Julia's macros seem to suggest that one could build a macro which transforms such a "generator" function into an julia iterator.
[It even seems like you could easily <strong>inline</strong> iterators written in function style, which is a feature the Iterators.jl package also tries to provide for its specific iterators <a href="https://github.com/JuliaCollections/Iterators.jl#the-itr-macro-for-automatic-inlining-in-for-loops" rel="noreferrer">https://github.com/JuliaCollections/Iterators.jl#the-itr-macro-for-automatic-inlining-in-for-loops</a> ]</p>

<p>Just to give an example of what I have in mind:</p>

<pre><code>@asiterator function myiterator(as::Array)
  b = 1
  for (a1, a2) in zip(as, as[2:end])
    try
      @produce a1[1] + a2[2] + b
    catch exc
    end
  end
end

for i in myiterator([(1,2), (3,1), 3, 4, (1,1)])
   @show i
end
</code></pre>

<p>where <code>myiterator</code> should ideally create a fast iterator with as low overhead as possible. And of course this is only one specific example. I ideally would like to have something which works with all or almost all generator functions.</p>

<p>The currently recommended way to transform a generator function into an iterator is via Julia's Tasks, at least to my knowledge. However they also seem to be way slower then pure iterators. For instance if you can express your function with the simple iterators like <code>imap</code>, <code>chain</code> and so on (provided by <a href="https://github.com/JuliaCollections/Iterators.jl" rel="noreferrer"><code>Iterators.jl</code></a> package) this seems to be highly preferable.</p>

<p>Is it theoretically possible in julia to build a macro converting generator-style functions into flexible <strong>fast</strong> iterators?</p>

<p>Extra-Point-Question: If this is possible, could there be a generic macro which inlines such iterators?</p>
