Created
January 16, 2019 16:57
-
-
Save gvx/6d2c6a107e221d0ccbcba9f6ca3ca642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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