bind()
Bind a function to a context with optional pre-filled arguments.
Implementation
Args: func: The function to bind context: The context to bind to (not used in Python implementation) *args: Arguments to pre-fill Returns: A bound function
Example
def add(x, y):
return x + y
bound_add = bind(add, None, 1)
bound_add(2)
Expected output: 3
Source Code
def bind(func: Callable, context: Any, *args) -> Callable:
def bound_func(*extra_args):
return func(*(args + extra_args))
return bound_func