Created
October 26, 2017 12:48
-
-
Save dmoisset/bd43b8c0ce26c9cff0ad297b7e1ba5f9 to your computer and use it in GitHub Desktop.
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
# Build functions that can be applied with **, mimicing the dollar operator in Haskell | |
class ApplyableFunc(): | |
def __init__(self, func): | |
self.func = func | |
def __call__(self, *args, **kwargs): | |
return self.func(*args, **kwargs) | |
def __pow__(self, arg): | |
return self.func(arg) | |
len = ApplyableFunc(len) | |
print(len("Hello")) | |
print(len ** "Hello") | |
print = ApplyableFunc(print) | |
print ** len ** "Hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment