Created
September 3, 2009 12:58
-
-
Save NicolasT/180283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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