I have a generator function that goes something like this:
def mygenerator():
next_value = compute_first_value() # Costly operation
while next_value
I needed something similar. This is what I landed on. Push the generator function into an inner and return it's call.
def mygenerator():
next_value = compute_first_value()
def generator():
while next_value != terminating_value:
yield next_value
next_value = compute_next(next_value)
return generator()