Created
November 23, 2018 21:56
-
-
Save cjw296/0d5914bfc85ffd344da5ad860423bccb 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
switch = Switch({ | |
'foo': lambda x: x+1, | |
}) | |
switch['foo']('bar') | |
switch = Switch() | |
@switch.handles('foo') | |
def handle_foo(x): | |
return x+1 | |
@switch.default() | |
def handle_others(): | |
pass | |
class MyThing(Switch): | |
@handles('foo') | |
def handles(self, x): | |
return x+1 | |
MyThing('foo')('whatever') | |
class MoarThingz(object): | |
switch = Switch() | |
def __init__(self, state): | |
self.state = state | |
@switch.handles('foo') | |
def handle_foo(self): | |
... | |
def dispatch(self, whatever, etc): | |
payload = decode(whatever, etc) | |
self.switch['foo'](payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment