Я был встревожен, осознав, что почти ни одна из встроенных библиотек Python не является типовой. с аннотациями.
Это моя попытка реализации:
Код: Выделить всё
def reduce(self, func: Callable[[list[T], list[T]], list[T]] = lambda x, y: x + y, default: Optional[T] = None) -> 'List[T]': # type: ignore
from functools import reduce
if default is None: return List(reduce(func, self.list)) # type: ignore
return List(reduce(func, self.list, default)) # type: ignore
Код: Выделить всё
a: List[str] = List(['a', 'b'])
b = a.reduce(lambda x, y: x + y)
Подробнее здесь: https://stackoverflow.com/questions/770 ... e-function