Created
March 29, 2023 12:39
-
-
Save FuruNov/6b1d7f624a3737299ef9cc945eb7eedb 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
| def curry(func): | |
| def curried(*args): | |
| if len(args) == func.__code__.co_argcount: | |
| return func(*args) | |
| return lambda x: curried(*args, x) | |
| return curried | |
| @curry | |
| def add(x, y): | |
| return x + y | |
| print(add(1)(2)) # 3 と出力される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment