Last active
August 29, 2015 14:01
-
-
Save tioover/76adee6b1ac3251e11c2 to your computer and use it in GitHub Desktop.
This file contains 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
def framework(): | |
pipeline = [] | |
register = lambda test, handler: pipeline.append((test, handler)) | |
def processing(*args): | |
for test, handler in pipeline: | |
tested = test(*args) | |
if tested is not False: | |
return handler(*args) | |
return register, processing | |
# use | |
register, hander = framework() | |
def sign(test): | |
def wrap(f): | |
register(test, f) | |
return f | |
return wrap | |
@sign(lambda x: x % 2) | |
def odd(x): | |
print(x) | |
for i in range(10): | |
handler(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment