21 lines
496 B
Python
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)
|