Luca Vehbiu
12/01/2023, 8:14 AMMarvin
12/01/2023, 8:15 AM.map()
function with tasks to automatically create a task run for each element of its input data. Mapped tasks represent the computations of many individual children tasks. Here's a simple example:
from prefect import flow, task
@task
def print_nums(nums):
for n in nums:
print(n)
@task
def square_num(num):
return num**2
@flow
def map_flow(nums):
print_nums(nums)
squared_nums = square_num.map(nums)
print_nums(squared_nums)
map_flow([1,2,3,5,8,13])
In this example, the square_num
task is mapped over the input list, creating a task run for each number in the list.
As for mapping over flows, Prefect doesn't have a direct equivalent. However, you can use subflows, which are just flows called from within a flow. You can pass results from other tasks to your subflow, effectively creating a similar behavior to mapping over tasks.
For more information, you can check out the Prefect documentation on flows and tasks.Luca Vehbiu
12/01/2023, 8:24 AM