unary()
Create a function that accepts only the first argument, ignoring others.
Implementation
Args: func: The function to cap arguments for Returns: A function that accepts only one argument
Example
def add_all(*args):
return sum(args)
first_only = unary(add_all)
first_only(1, 2, 3, 4) # Only uses first argument
Expected output: 1
Source Code
def unary(func: Callable) -> Callable:
_validate_callable(func)
def wrapper(arg, *ignored_args, **kwargs):
return func(arg, **kwargs)
return _copy_function_metadata(wrapper, func)