38 lines
997 B
Python
38 lines
997 B
Python
from typing import Generic, TypeVar
|
|
|
|
from rainbowadn.core import *
|
|
from rainbowadn.flow.core import *
|
|
from ._verification import *
|
|
from ._verifyreduce import *
|
|
|
|
__all__ = ('ReduceVerification',)
|
|
|
|
Verified = TypeVar('Verified')
|
|
|
|
|
|
class ReduceVerification(
|
|
Verification[Reducer[Verified, bool]],
|
|
Generic[Verified],
|
|
):
|
|
def __init__(
|
|
self,
|
|
verification: Verification[Verified]
|
|
):
|
|
assert isinstance(verification, Mapper)
|
|
self.verification = verification
|
|
|
|
@classmethod
|
|
def _verify_reduce(cls) -> Reduce[bool, bool]:
|
|
return VerifyReduce()
|
|
|
|
def _reduce(self) -> Reduce[Verified, bool]:
|
|
return MapReduce(self.verification, self._verify_reduce())
|
|
|
|
async def verify(self, element: Reducer[Verified, bool]) -> bool:
|
|
assert isinstance(element, Reducer)
|
|
assert_true(await element.reduce(self._reduce()))
|
|
return True
|
|
|
|
def loose(self) -> Verification[Reducer[Verified, bool]]:
|
|
return self
|