Skip to content

Instantly share code, notes, and snippets.

@gvx
Created January 16, 2019 16:57
Show Gist options
  • Save gvx/6d2c6a107e221d0ccbcba9f6ca3ca642 to your computer and use it in GitHub Desktop.
Save gvx/6d2c6a107e221d0ccbcba9f6ca3ca642 to your computer and use it in GitHub Desktop.
@dataclass
class Curried:
f: Callable
def __call__(self, *args, **kwargs):
f = partial(self.f, *args, **kwargs)
try:
signature(f).bind()
except TypeError:
return type(self)(f)
else:
return f()
from curry import Curried
def foo(a, b, c):
return (a, b, c)
def bar(a, b=10, *, c):
return (a, b, c)
print(Curried(foo)(1)(2)(3)) # (1, 2, 3)
print(Curried(bar)(c=3)(1, 2)) # (1, 2, 3)
print(Curried(foo)(c=3)(a=1, b=2)) # (1, 2, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment