Skip to content

Instantly share code, notes, and snippets.

@atdt
Created October 29, 2011 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atdt/1324228 to your computer and use it in GitHub Desktop.
Save atdt/1324228 to your computer and use it in GitHub Desktop.
partial operator
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