<@U06RKAMK0UC> how would i pass a static value in ...
# ask-ai
c
@ancient-wolf-19325 how would i pass a static value in as an argument to a function being used with map_task
a
To pass a static value as an argument to a function used with
map_task
, use
functools.partial
to bind the static argument before mapping. For example, if your task takes multiple arguments but you want to map over only one, partially apply the static arguments and map over the dynamic one. This is the recommended approach since
map_task
only supports mapping over a single input; all other arguments must be fixed via partial binding. See the example below:
Copy code
from functools import partial
from flytekit import task, workflow, map_task

@task
def my_task(x: int, y: str) -> str:
    return f"{x}-{y}"

@workflow
def wf(xs: list[int], y: str) -> list[str]:
    partial_task = partial(my_task, y=y)
    return map_task(partial_task)(x=xs)
According to the Flyte documentation, this is the standard way to pass static arguments to a mapped task. Note: you cannot provide a list as a static input to a partial task. Would you like more detail or examples for other scenarios? Sources: - Flyte map tasks documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.