From 1644c904de1544f788a8e88aa6c52bcd6a625b93 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 28 Dec 2022 13:31:29 +0100 Subject: Day 21 [WIP] --- aoc/decorators.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'aoc') diff --git a/aoc/decorators.py b/aoc/decorators.py index a31993a..42603c2 100644 --- a/aoc/decorators.py +++ b/aoc/decorators.py @@ -1,11 +1,15 @@ # -*- coding: utf-8 -*- from functools import wraps -from typing import Iterator, TypeVar, Callable +from typing import Iterator, TypeVar, Callable, List T = TypeVar("T") +I = TypeVar("I") +AssignmentRun = Callable[[Iterator[I], ...], Iterator[T]] +AssignmentRunList = Callable[[List[I], ...], Iterator[T]] -def infinite_generator(func: Callable[[...], Iterator[T]]): + +def infinite_generator(func: AssignmentRun) -> AssignmentRun: @wraps(func) def wrapper(*args, **kwargs): items = list(func(*args, **kwargs)) @@ -15,3 +19,12 @@ def infinite_generator(func: Callable[[...], Iterator[T]]): yield item return wrapper + + +def list_input(func: AssignmentRun) -> AssignmentRunList: + @wraps(func) + def wrapper(self, input: Iterator, *args, **kwargs) -> T: + + return func(self, list(input), *args, **kwargs) + + return wrapper -- cgit v1.2.3