Skip to content

Instantly share code, notes, and snippets.

@3noch
Last active August 29, 2015 14:00
Show Gist options
  • Save 3noch/f71c844d593c13dfa5d8 to your computer and use it in GitHub Desktop.
Save 3noch/f71c844d593c13dfa5d8 to your computer and use it in GitHub Desktop.
def match(fns):
def inner(x):
for cls, fn in fns:
if isinstance(x, cls):
return fn(x)
return inner
doformat = match(
[ (Literal, lambda x: x)
, (AllOf: lambda x: ' and '.join(doformat(y) for y in x))
, (Enum: lambda x: ....)
])
doformat(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment