There are methods that accept a single argument and behave like a binary operation or a predicate. It would be useful to be able to turn them into binary functions for use with higher-order functions like map and reduce:
reduce(methodcaller("combine"), objs) # reduce a sequence using "combine" method
map(methodcaller("combine"), alist, blist) # combine pairs of elements
all(map(methodcaller("compatible_with"), alist, blist)) # check that pairs of elements are compatible
This functionality is already available for overloaded operators, because operator module provides them as functions. Some methods behave similarly to operators, so I think that a similar functionality should be available for them as well. |