Skip to content

Instantly share code, notes, and snippets.

@cjw296
Created November 23, 2018 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjw296/0d5914bfc85ffd344da5ad860423bccb to your computer and use it in GitHub Desktop.
Save cjw296/0d5914bfc85ffd344da5ad860423bccb to your computer and use it in GitHub Desktop.
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