Typehint generic type variable
You can do this with TypeVar
from typing import Callable, List, TypeVar
T = TypeVar('T')
V = TypeVar('V')
def mymap(items: List[T], fn: Callable[[T], V]) -> List[V]:
return [fn(e) for e in items]
You can do this with TypeVar
from typing import Callable, List, TypeVar
T = TypeVar('T')
V = TypeVar('V')
def mymap(items: List[T], fn: Callable[[T], V]) -> List[V]:
return [fn(e) for e in items]