title: Generator functions in R
body: <p>Is there a package or language construct in R that facilitates or provides the implementation of "<a href="http://docs.python.org/3/tutorial/classes.html#generators" rel="noreferrer">Python-like generators</a>"?</p>
  
  <p>By "Python-like generators" I mean functions that keep state between calls, in R syntax and borrowing the keyword <strong>yield</strong> from Python will be something like:</p>
  
  <pre><code>iterable.fun &lt;- function(){
    yield list('a','b','c')
  }
  </code></pre>
  
  <p>With <strong>yield</strong> instead of a <strong>return</strong>, then calling the function three consecutive times would give:</p>
  
  <pre><code>&gt; iterable.fun()
    'a'
  &gt; iterable.fun()
    'b'
  &gt; iterable.fun()
    'c'
  </code></pre>
  
  <p>Edit: I left out an aspect of Python generators that makes them different from iterators. It is that the whole list of objects to iterate on is not built on the first call and then iterated, but each function call creates the one element that will return for that call.</p>