Skip to content

Instantly share code, notes, and snippets.


pervognsen/ Secret

Created Aug 22, 2012
What would you like to do?
inf = float("+inf")
def fix(bottom, n=inf, unwrap=lambda x: x):
if not callable(bottom):
bottom_value = bottom
bottom = lambda *args: bottom_value
def decorator(f):
def f_fix(*args):
me = (f_fix, args)
if not fix.calling:
value, fix.values[me] = None, bottom(*args)
i = 0
while i < n and value != fix.values[me]:
value, fix.values[me] = fix.values[me], unwrap(f(*args))
i += 1
return value
if me in fix.calling:
return fix.values.get(me, bottom(*args))
value = fix.values[me] = unwrap(f(*args))
return value
return f_fix
return decorator
fix.calling = set()
fix.values = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment