Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Created March 23, 2015 02:25
Show Gist options
  • Save skatenerd/c5c8e7a29d0e013391dc to your computer and use it in GitHub Desktop.
Save skatenerd/c5c8e7a29d0e013391dc to your computer and use it in GitHub Desktop.
Lifting "&" to apply to functions
class CombinableFunction(object):
def __init__(self, function):
self.function = function
def __call__(self, *args):
return self.function(*args)
def __or__(self, other):
def new_function(*args):
return self.function(*args) | other(*args)
return CombinableFunction(new_function)
def __and__(self, other):
def new_function(*args):
return self.function(*args) & other(*args)
return CombinableFunction(new_function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment