Skip to content

pydsa.generators

T module-attribute

T = TypeVar('T')

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.mu
 8
 9
10
11
12
13
14
15
16
def as_list(f: Callable[..., Iterator[T]]) -> Callable[..., [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, **kwargs) -> [T]: list(f(*args, **kwargs))
  wrapper
 8
 9
10
11
12
13
14
15
16
17
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, **kwargs) -> list[T]:
        return list(f(*args, **kwargs))
    return wrapper