This commit is contained in:
Ruediger Ludwig 2022-11-30 19:39:52 +01:00
commit a355de5d8b
24 changed files with 1133 additions and 0 deletions

31
advent/common/provider.py Normal file
View file

@ -0,0 +1,31 @@
from abc import abstractmethod
from typing import Iterable, Iterator, Protocol, TypeVar
T = TypeVar('T', covariant=True)
class EofException(Exception):
pass
class Provider(Iterator[T], Iterable[T], Protocol[T]):
@abstractmethod
def peek(self) -> T:
...
@abstractmethod
def get(self) -> T:
...
@abstractmethod
def finished(self) -> bool:
...
def __next__(self) -> T:
if self.finished():
raise StopIteration()
return self.get()
def __iter__(self):
return self