https://dagster.io/ logo
#ask-ai
Title
# ask-ai
b

BC A

03/13/2024, 8:50 PM
@Scout can you do a conditial yielding using this example ? :
Copy code
def multiple_dynamic_values():
    for i in range(2):
        yield DynamicOutput(i, output_name="values", mapping_key=f"num_{i}")
        yield DynamicOutput(-i, output_name="negatives", mapping_key=f"neg_{i}")
s

Scout

03/13/2024, 8:50 PM
Yes, you can perform conditional yielding in the example you provided. Conditional yielding means that you yield
DynamicOutput
objects based on some condition. Here's a modified version of your example that includes a conditional statement:
Copy code
python from dagster import DynamicOutput, op  @op(out={"values": DynamicOut(), "negatives": DynamicOut()}) def multiple_dynamic_values():     for i in range(2):         if some_condition(i):             yield DynamicOutput(i, output_name="values", mapping_key=f"num_{i}")         if another_condition(i):             yield DynamicOutput(-i, output_name="negatives", mapping_key=f"neg_{i}")
In this code,
some_condition(i)
and
another_condition(i)
represent placeholder functions that return a boolean value. If
some_condition(i)
returns
True
, then a
DynamicOutput
with the value
i
is yielded for the output named "values". Similarly, if
another_condition(i)
returns
True
, then a
DynamicOutput
with the value
-i
is yielded for the output named "negatives". You would need to define the actual conditions that
some_condition(i)
and
another_condition(i)
check for based on your specific use case.