Skip to content

Switch composer

Fluent Switch builder for Composer.

This module defines SwitchComposer, a small builder used by Composer to add multi-branch conditional steps fluently.

Note

This builder is not meant to be instantiated directly by users. Use Composer.switch(...) to obtain an instance and add cases/default before calling .end().

Authors

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

SwitchComposer(parent, condition, output_state=None, input_map=None, retry_config=None, error_handler=None, cache_store=None, cache_config=None, name=None)

Fluent builder for a switch conditional.

Usage

composer.switch(cond).case("A", step_a).case("B", step_b).end()

Optionally call .default(...) to set a fallback branch.

Initialize the SwitchComposer.

Parameters:

Name Type Description Default
parent Composer

The parent composer instance.

required
condition Component | Callable[[dict[str, Any]], str]

The condition to evaluate.

required
output_state str | None

Optional state key to store condition result. Defaults to None.

None
input_map InputMapSpec | None

Unified input mapping for the condition. Defaults to None.

None
retry_config RetryConfig | None

Retry configuration. Defaults to None.

None
error_handler BaseStepErrorHandler | None

Error handler. Defaults to None.

None
cache_store BaseCache | None

Optional cache store. Defaults to None.

None
cache_config dict[str, Any] | None

Optional cache config. Defaults to None.

None
name str | None

Optional name for the resulting step. Defaults to None, in which case a name will be auto-generated with the prefix "Switch_".

None

case(key, branch)

Add a case branch.

Parameters:

Name Type Description Default
key str

Case key to match against condition result.

required
branch BasePipelineStep | list[BasePipelineStep]

Step(s) to execute for this case.

required

Returns:

Name Type Description
Self Self

The builder instance for chaining.

default(branch)

Set the default branch for unmatched cases.

Parameters:

Name Type Description Default
branch BasePipelineStep | list[BasePipelineStep]

Default fallback branch.

required

Returns:

Name Type Description
Self Self

The builder instance for chaining.

end()

Finalize and append the switch conditional to the parent composer.

Returns:

Name Type Description
Composer Composer

The parent composer for continued chaining.