https://prefect.io logo
Title
j

Jerry Thomas

08/22/2019, 4:49 AM
Hi, is there a way to pass values instead of arrays for tasks that use map. Map passes items of a list to a task and I have a situation where I have a function that has two parameters and I want the data parameter to be split across multiple instances but the value parameter to be same across all tasks. I can achieve this by using the example below
python
@task
def convert(data, value):
    data['x'] *= value
    return data

data = [{"x": x, "y": x % 5, "z": x % 3} for x in range(10)]

with Flow("convert-using-value") as flow:
    res = convert.map(data, [2 for i in range(10)])
However, it there a better way to say mark the value parameter to be shared across multiple executions for a call.
j

Jeremiah

08/22/2019, 1:07 PM
Hi @Jerry Thomas — yup, Prefect has an
unmapped
operator for exactly this situation. Here are the [relevant docs](https://docs.prefect.io/guide/core_concepts/mapping.html#unmapped-inputs). I think you’ll simply need to call
value=unmapped([2 for i in range(10)])
.
👍 1
j

Jerry Thomas

08/23/2019, 6:37 AM
Awesome. Thanks