Skip to content

Instantly share code, notes, and snippets.

@dmoisset
Created October 26, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmoisset/bd43b8c0ce26c9cff0ad297b7e1ba5f9 to your computer and use it in GitHub Desktop.
Save dmoisset/bd43b8c0ce26c9cff0ad297b7e1ba5f9 to your computer and use it in GitHub Desktop.
# 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