partial#

swordfish.partial(func, *args, **kwargs)#

Creates a partially applied function by binding arguments to the original function.

参数:
  • func (FunctionDef) -- The original function to partially apply arguments to.

  • *args -- Positional arguments to bind to the function.

  • **kwargs -- Keyword arguments to bind to the function.

返回:

A Swordfish FunctionDef object representing the partially applied function.

返回类型:

FunctionDef

示例

>>> import swordfish as sf
>>> import swordfish.function as F
>>> @F.swordfish_udf
>>> def add(a,b):
...    return a+b
>>> partial_func1 = sf.partial(add, 1)
>>> partial_func1(3)
Long(4)
>>> partial_func2 = sf.partial(add, b=4)
>>> partial_func2(3)
Long(7)