We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 13c6e29 commit abfb726Copy full SHA for abfb726
src/adventofcode/util/helpers.py
@@ -2,7 +2,7 @@
2
import os
3
import pstats
4
import time
5
-from typing import Callable, Literal
+from typing import Callable, Literal, Dict, Any
6
7
from adventofcode.config import RUNNING_ALL
8
from adventofcode.util.console import console
@@ -93,3 +93,17 @@ def wrapper(*args, **kwargs):
93
return wrapper
94
95
return decorator
96
+
97
98
+def memoize(func: Callable): # type: ignore
99
+ cache: Dict[Any, Any] = dict()
100
101
+ def memoized_func(*args):
102
+ if args in cache:
103
+ return cache[args]
104
105
+ result = func(*args)
106
+ cache[args] = result
107
+ return result
108
109
+ return memoized_func
0 commit comments