diff --git a/src/functional/11_run_once.py b/src/functional/11_run_once.py new file mode 100644 index 0000000..1b94826 --- /dev/null +++ b/src/functional/11_run_once.py @@ -0,0 +1,21 @@ +import functools + +def run_once(f): + already_run = False + + @functools.wraps(f) + def wrapper(*args, **kwargs): + nonlocal already_run + + if not already_run: + already_run = True + return f(*args, **kwargs) + + return wrapper + +@run_once +def test(): + print("Hello World!") + +test() +test() \ No newline at end of file