Initial
This commit is contained in:
commit
a355de5d8b
24 changed files with 1133 additions and 0 deletions
31
advent/common/provider.py
Normal file
31
advent/common/provider.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue