Created
November 8, 2010 16:48
-
-
Save philchristensen/667924 to your computer and use it in GitHub Desktop.
sketch idea for implementing case/switch with Python decorators
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
case_dict = {} | |
def case(key=None): | |
def case_builder(func): | |
case_dict[key] = func | |
return func | |
return case_builder | |
def switch(value): | |
return case_dict[value] | |
def example_switch(value): | |
@case('something') | |
def something_func(): | |
print 'this is something' | |
@case('something else') | |
def something_func(): | |
print 'this is something else' | |
switch(value)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment