Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created January 17, 2024 19:14
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 nelhage/4855a17d4982b804216b778c8d814d43 to your computer and use it in GitHub Desktop.
Save nelhage/4855a17d4982b804216b778c8d814d43 to your computer and use it in GitHub Desktop.
# before
def my_decorator(f):
def wrapper(*args, **kwds):
print('Calling decorated function')
return f(*args, **kwds)
return wrapper
# but why not
def my_decorator(f)(*args, **kwds):
print('Calling decorated function')
return f(*args, **kwds)
# of course we can go full Haskell
def foldl(f)(seed)(lst):
x = seed
for v in lst:
x = f(seed, x)
return x
import operator
sum = foldl(operator.add)(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment