Created
October 1, 2020 12:51
-
-
Save dschep/87d25830e8782075e978f404af3e8432 to your computer and use it in GitHub Desktop.
A decorator version of functools.partial
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
def partially(*args, **kwargs): | |
""" | |
A decorator version of functools.partial | |
eg, this: | |
def _foo(x, y): | |
pass | |
foo = partial(_foo, 1) | |
is the same as: | |
@partially(1) | |
def foo(x, y): | |
pass | |
""" | |
return lambda func: partial(func, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment