title: Python Generator "chain" in a for loop
body: <p>I'm trying to set up a "processing pipeline" for data that I'm reading in from a data source, and applying a sequence of operators (using generators) to each item as it is read. </p>
  
  <p>Some sample code that demonstrates the same issue. </p>
  
  <pre><code>def reader():
      yield 1
      yield 2
      yield 3
  
  def add_1(val):
      return val + 1
  
  def add_5(val):
      return val + 5
  
  def add_10(val):
      return val + 10
  
  operators = [add_1, add_5, add_10]
  
  def main():
      vals = reader()
  
      for op in operators:
          vals = (op(val) for val in vals)
  
      return vals
  
  print(list(main()))
  </code></pre>
  
  <p><strong>Desired</strong> : <code>[17, 18, 19]</code><br>
  <strong>Actual</strong>: <code>[31, 32, 33]</code></p>
  
  <p>Python seems to not be saving the value of <code>op</code> each time through the for loop, so it instead applies the third function each time. <strong>Is there a way to "bind" the actual operator function to the generator expression each time through the for loop?</strong></p>
  
  <p>I could get around this trivially by changing the generator expression in the for loop to a list comprehension, but since the actual data is much larger, I don't want to be storing it all in memory at any one point.</p>