Created
January 17, 2024 19:14
-
-
Save nelhage/4855a17d4982b804216b778c8d814d43 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
# 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