【发布时间】:2015-03-04 21:05:10
【问题描述】:
我使用 Python 是因为它通常易于阅读,但这不是 Python 特定的问题。
取下面的Python函数strip_argument:
def strip_argument(func_with_no_args):
return lambda unused: func_with_no_args()
在使用中,我可以将一个无参数函数传递给strip_argument,它会返回一个接受一个从未使用过的参数的函数。例如:
# some API I want to use
def set_click_event_listener(listener):
"""Args:
listener: function which will be passed the view that was clicked.
"""
# ...implementation...
# my code
def my_click_listener():
# I don't care about the view, so I don't want to make that an arg.
print "some view was clicked"
set_click_event_listener(strip_argument(my_click_listener))
函数strip_argument 有标准名称吗?我对标准库中具有此类功能的任何语言都感兴趣。
【问题讨论】: