Created
July 19, 2020 20:43
-
-
Save marethyu/ffca5129bce370635b1cfd4feb2b1700 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 uhm(f): | |
| class Wrapper: | |
| def __getitem__(self, arg): | |
| if arg is None: | |
| return f() | |
| elif isinstance(arg, tuple): | |
| return f(*arg) | |
| else: | |
| return f(arg) | |
| return Wrapper() | |
| @uhm | |
| def hello(name): | |
| print(f'hello {name}!') | |
| @uhm | |
| def repeat(name, times): | |
| for _ in range(times): | |
| hello[name] | |
| @uhm | |
| def print_smth(): | |
| print('something') | |
| @uhm | |
| def sqrt(n, iterations): | |
| guess = 10.0 | |
| for _ in range(iterations): | |
| guess = guess - (guess * guess - n) / (2.0 * guess) | |
| return guess | |
| hello['jimmy'] | |
| repeat['bob', 10] | |
| print_smth[None] | |
| print(sqrt[25.0, 20]) | |
| print(sqrt[50.0, 15]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment