Skip to content

Instantly share code, notes, and snippets.

@RemyPorter
Created October 1, 2014 01:41
Show Gist options
  • Save RemyPorter/562b2979b12c16471d93 to your computer and use it in GitHub Desktop.
Save RemyPorter/562b2979b12c16471d93 to your computer and use it in GitHub Desktop.
class EffectCompose(EffectMeta):
def __init__(cls, name, bases, dct):
super().__init__(name, bases, dct)
def compose(a,b,abort_on_fail=False):
if not a:
return b
if abort_on_fail:
def f(statecont, *args, **kwargs):
res = a(statecont)
if res.opstate:
return b(res)
else:
def f(statecont, *args, **kwargs):
return b(a(statecont))
return f
behaviors = dct["behaviors"]
d = ""
f = None
for b in behaviors:
f = compose(f, b)
d += "\n{0}".format(b.__doc__)
def call(self, state, *args, **kwargs):
return f(state, *args, **kwargs)
def init(self):
pass
cls.__init__ = init
cls.__call__ = call
cls.__doc__ = d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment