title: Detect if generator function is empty, otherwise iterate over it
body: <p>Let us suppose we have a generator function <code>gen()</code>, which we do not know if it is empty or not.</p>
  
  <p>If it is empty, we would like to execute a special function <code>foo()</code>, and otherwise we would like to execute a function over each element of the iterator <code>bar(elem)</code>.</p>
  
  <p>I can do it like this:</p>
  
  <pre><code>is_empty = True
  for elem in gen():
      is_empty = False
      bar(elem)
  if is_empty: foo()
  </code></pre>
  
  <p>But that does not feel very pythonic. Any other approach?</p>