Add uncurry2

This commit is contained in:
Emi Simpson 2023-03-05 21:17:02 -05:00
parent 8d3edb1ea8
commit 46bbcca1b8
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -140,6 +140,20 @@ def cur3(f: Callable[Concatenate[A, B, P], D]) -> Callable[[A], Callable[[B], Ca
"""
return p(p, p, f) #type:ignore
def uncurry2(f: Callable[[A], Callable[P, B]]) -> Callable[Concatenate[A, P], B]:
"""
Uncurries a two-argument function
The inverse of `cur2`
>>> uncurry2(lambda x: lambda y: f'{x} {y}')('hello', 'world')
'hello world'
"""
@wraps(f)
def inner(a: A, *args: P.args, **kwargs: P.kwargs) -> B:
return f(a)(*args, **kwargs)
return inner
# Curried versions of map & filter with stricter types
def p_map(f: Callable[[A], B]) -> Callable[[Sequence[A]], Sequence[B]]: