rainbowadn/rainbowadn/flow/core/_callablemapper.py
2022-12-22 21:48:40 +00:00

21 lines
496 B
Python

from typing import Callable, Generic, TypeVar
from ._mapper import Mapper
__all__ = ('CallableMapper',)
Element = TypeVar('Element', contravariant=True)
Mapped = TypeVar('Mapped', covariant=True)
class CallableMapper(
Mapper[Element, Mapped],
Generic[Element, Mapped]
):
def __init__(self, target: Callable[[Element], Mapped]):
assert callable(target)
self.target = target
async def map(self, element: Element) -> Mapped:
return self.target(element)