<@ULVA73B9P> Finished in state Failed(“Flow run en...
# ask-marvin
l
@Marvin Finished in state Failed(“Flow run encountered an exception. AttributeError: ‘Flow’ object has no attribute ‘map’\n”) Is there a map equivalent of tasks for flows?
m
In Prefect, you can use the
.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:
Copy code
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.
l
can you give me an example with subflows