Created
October 29, 2011 08:21
-
-
Save atdt/1324228 to your computer and use it in GitHub Desktop.
partial operator
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 partial_operator(oper, b): | |
""" Returns a partially applied operator with the first parameter | |
unspecified. Example:: | |
>>> less_than_ten = partial_operator(operator.lt, 10) | |
The operator is annotated with an attribute 'b' which contains the | |
partially applied operand. """ | |
@wraps(oper) | |
def wrapped(a): | |
return oper(a, b) | |
wrapped.b = b | |
return wrapped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment