# partial

Starlark module for working with partial function objects. Partial function objects allow some parameters are bound before the call.

Similar to [partial](https://docs.python.org/3/library/functools.html#functools.partial).

## partial.call(partial, \*args, \*\*kwargs)

Calls a partial created using make.

**Parameters:**

* **partial** – the partial to be called.
* \***args** – additional positional arguments to be appended to the ones given to make.
* \*\***kwargs** – additional keyword arguments to augment and override the ones given to make.

*Returns:* whatever the function in the partial returns.

## partial.make(func, \*args, \*\*kwargs)¶

Creates a partial that can be called using call. A partial can have args assigned to it at the make site, and can have args passed to it at the call sites.

Examples(a partial ‘function’ can be defined with positional args and kwargs):

```python
# function with no args
def function1():
    ...
# function with 2 args
def function2(arg1, arg2):
    ...
# function with 2 args and keyword args
def function3(arg1, arg2, x, y):
    ...
```

The positional args passed to the function are the args passed into make followed by any additional positional args given to call.

Example(function with two positional arguments where one is supplied by make and the other by call):

```python
# function demonstrating 1 arg at make site, and 1 arg at call site
def _foo(make_arg1, func_arg1):
...     print(make_arg1 + " " + func_arg1 + "!")
hi_func = partial.make(_foo, "Hello")
bye_func = partial.make(_foo, "Goodbye")
partial.call(hi_func, "Jennifer")
"Hello, Jennifer!"
partial.call(hi_func, "Dave")
"Hello, Dave!"
partial.call(bye_func, "Jennifer")
"Goodbye, Jennifer!"
partial.call(bye_func, "Dave")
"Goodbye, Dave!"
```

The keyword args given to the function are the kwargs passed into make unioned with the keyword args given to call. In case of a conflict, the keyword args given to call take precedence. This allows you to set a default value for keyword arguments and override it at the call site.

Example(function with a make site arg, a call site arg, a make site kwarg and a call site kwarg):

```python
def _foo(make_arg1, call_arg1, make_location, call_location):
...     print(make_arg1 + " is from " + make_location + " and " + call_arg1 + " is from " + call_location + "!")
func = partial.make(_foo, "Ben", make_location="Hollywood")
partial.call(func, "Jennifer", call_location="Denver")
"Ben is from Hollywood and Jennifer is from Denver!"
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
"Ben is from LA and Jennifer is from Denver!".
```

Note that keyword args may not overlap with positional args, regardless of whether they are given during the make or call step. For instance, you can’t do:

```python
def foo(x):
    pass
func = partial.make(foo, 1)
partial.call(func, x=2)
```

**Parameters:**

* **func** – the function to be called.
* \***args** – positional arguments to be passed to function.
* \*\***kwargs** – keyword arguments to be passed to function. Note that these can be overridden at the call sites.

*Returns:* a new partial that can be called using call.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/partial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
