Created
March 23, 2015 02:25
-
-
Save skatenerd/c5c8e7a29d0e013391dc to your computer and use it in GitHub Desktop.
Lifting "&" to apply to functions
This file contains hidden or 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
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