<@ULVA73B9P> how do i pass a mapped parameter resu...
# ask-marvin
g
@Marvin how do i pass a mapped parameter result on to a non-mapped function on prefect 1
m
To pass a mapped parameter result to a non-mapped function in Prefect 1.x, you can chain tasks using the
set_dependencies
method to ensure the correct order of execution. In Prefect 1.x, mapping allows you to apply a task to each element of a list individually. To pass its result to a non-mapped task, you generally collect or reduce the results into a single output. Here's a brief overview: 1. Mapping: Use the
map
method to execute a task over a collection of inputs. 2. Reducing: Collect the mapped outputs if necessary. This step might involve concatenating lists or picking specific elements. 3. Chaining: Use the
set_dependencies
method to ensure your non-mapped task runs after the mapped task completes. Here's an example scenario:
Copy code
python
from prefect import Task, Flow

class MultiplyByTwo(Task):
    def run(self, x):
        return x * 2

class CollectResults(Task):
    def run(self, results):
        return sum(results)

with Flow("example") as flow:
    inputs = [1, 2, 3]
    mapped_results = MultiplyByTwo.map(inputs)
    final_result = CollectResults(upstream_tasks=[mapped_results])

flow.run()
In this example, the
MultiplyByTwo
task is mapped over the list of inputs, and the
CollectResults
task processes the output of the mapped task sequence. Since Prefect 1.x is relatively older, you won't find abundant recent documentation or GitHub activity. However, for detailed examples or troubleshooting, consider visiting the Prefect 1.x documentation or forums directly. I can't search Prefect 1.x specific resources, but you may want to check the Prefect Discourse forums for more assistance! If you have the option, consider upgrading to a more recent Prefect version for enhanced features and support.