This might just be too crazy to be possible but I figured it might be worth a try asking.
Lets say I have two functions, where solver evaluates objective arbitrary amount of times, and can be taken from various libraries (so I can't edit it).
def objective(x): return x**2
def solver(objective):
x = 100
for i in range(10):
# do stuff with x
value = objective(x)
is there any way to convert an arbitrary function like solver into a generator which yields each time it evaluates objective? This is what I want to convert it to:
def objective(x): return x**2
def solver(objective):
x = 100
for i in range(10):
# do stuff with x
value = objective(x)
yield