Kevin Mullins
01/27/2022, 5:20 PMfunction afunction bAnna Geller
with case(cond, True):
        val = function_a_decorated_with_task()
        another_action(val)
    with case(cond, False):
        val = function_b_decorated_with_task()
        another_action(val)Kevin Mullins
01/27/2022, 5:30 PMKevin Kho
Kevin Mullins
01/27/2022, 5:48 PMKevin Mullins
01/27/2022, 5:50 PMKevin Kho
Kevin Mullins
01/27/2022, 5:51 PMKevin Mullins
01/27/2022, 6:00 PMfrom typing import Any, Callable
import prefect
from prefect import task, Flow
def string_factory_one() -> str:
    return "return from string factory one"
def string_factory_two() -> str:
    return "return from string factory two"
@task
def determine_string_factory(value: int) -> Callable[[], str]:
    if value <= 5:
        prefect.context.logger.info("using string factory one")
        return string_factory_one
    prefect.context.logger.info("using string factory two")
    return string_factory_two
@task
def use_string_factory(string_factory: Callable[[], str]) -> None:
    value = string_factory()
    <http://prefect.context.logger.info|prefect.context.logger.info>(f"return from factory: {value}")
with Flow("test-callable-args") as flow:
    for i in range(10):
        factory = determine_string_factory(i)
        use_string_factory(factory)
if __name__ == "__main__":
    flow.run()Kevin Kho
