I’m trying to implement a helper function which partial apply arguments to a specific function and return a new function
from typing import Any, Callable, TypeVar
from typing_extensions import ParamSpec
P = ParamSpec('P')
R = TypeVar('R')
def partial_apply(fn: Callable[P, R], *args: subset_of[P.args], **kwargs: subset_of[P.kwargs]) -> Callable[remainder_of[P], R]:
def wrapper() -> R:
return fn(*args, **kwargs)
return wrapper
def add(a: int, b: int) -> int:
return a + b
add_1 = partial_apply(add, 1)
add_1(2) # 3
But subset_of
and remainder_of
is obviously not supported here, so is there any solution?