summaryrefslogtreecommitdiffstats
path: root/aoc/decorators.py
blob: a31993a48ca0234707e42834726a3469840431e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- coding: utf-8 -*-
from functools import wraps
from typing import Iterator, TypeVar, Callable

T = TypeVar("T")


def infinite_generator(func: Callable[[...], Iterator[T]]):
    @wraps(func)
    def wrapper(*args, **kwargs):
        items = list(func(*args, **kwargs))

        while True:
            for item in items:
                yield item

    return wrapper