UniCoreFW

memoize()

Cache the results of function calls.

Implementation

Args: func: The function to memoize Returns: A memoized version of the function

Example

memoize(lambda x: x * 2)(5)

Expected output: 10

Source Code

def memoize(func: Callable) -> Callable: cache = {} def memoized_func(*args): if args not in cache: cache[args] = func(*args) return cache[args] return memoized_func