24 lines
626 B
Python
24 lines
626 B
Python
from typing import Generic, TypeVar
|
|
|
|
from ._mapper import *
|
|
|
|
__all__ = ('Composition',)
|
|
|
|
Element = TypeVar('Element')
|
|
Middle = TypeVar('Middle')
|
|
Mapped = TypeVar('Mapped')
|
|
|
|
|
|
class Composition(
|
|
Mapper[Element, Mapped],
|
|
Generic[Element, Mapped, Middle]
|
|
):
|
|
def __init__(self, domain: Mapper[Element, Middle], codomain: Mapper[Middle, Mapped]):
|
|
assert isinstance(domain, Mapper)
|
|
assert isinstance(codomain, Mapper)
|
|
self.domain = domain
|
|
self.codomain = codomain
|
|
|
|
async def map(self, element: Element) -> Mapped:
|
|
return await self.codomain.map(await self.domain.map(element))
|