Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created September 3, 2009 12:58
Show Gist options
  • Save NicolasT/180283 to your computer and use it in GitHub Desktop.
Save NicolasT/180283 to your computer and use it in GitHub Desktop.
f1 = lambda a: a + 1.
f2 = lambda a: 1. / a
f3 = lambda a: 2. * a
apply_ = lambda *funs: lambda arg: funs[0](arg) if len(funs) == 1 \
else funs[-1](apply_(*funs[:-1])(arg))
t1 = apply_(f1, f2, f3)
print t1(-2.)
try:
print t1(-1.)
assert False
except ZeroDivisionError:
pass
print apply_(f3, f1, f2)(1.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment