Skip to content

pydsa.generators

as_list

as_list(
    f: Callable[..., Iterator[T]],
) -> Callable[..., List[T]]

Run a generator function to exhaustion and return its yields as a list.

A method that yields each answer as it finds it is returned whole, the way LeetCode expects it.

Source code in pydsa/generators.py
10
11
12
13
14
15
16
17
18
19
20
21
def as_list(f: Callable[..., Iterator[T]]) -> Callable[..., List[T]]:
    """Run a generator function to exhaustion and return its yields as a list.

    A method that yields each answer as it finds it is returned whole, the way
    LeetCode expects it.
    """

    @wraps(f)
    def wrapper(*args: Any, **kwargs: Any) -> List[T]:
        return list(f(*args, **kwargs))

    return wrapper