If else composer
Fluent If/Else builder for Composer.
This module defines IfElseComposer, a small builder used by Composer to add
an if/else conditional step fluently.
Note
This builder is not meant to be instantiated directly by users. Use
Composer.when(...) to obtain an instance and complete it with
.then(...), .otherwise(...), and .end().
References
NONE
IfElseComposer(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 an if/else conditional.
Usage
composer.when(cond).then(if_branch).otherwise(else_branch).end()
After setting both branches, call .end() to append the conditional step and
return back to the parent Composer.
Initialize the IfElseComposer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent |
Composer
|
The parent composer instance. |
required |
condition |
Component | Callable[[dict[str, Any]], bool]
|
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 "IfElse_". |
None
|
end()
Finalize and append the conditional step to the parent composer.
Returns:
| Name | Type | Description |
|---|---|---|
Composer |
Composer
|
The parent composer for continued chaining. |
otherwise(branch)
Define the branch to execute when the condition is false.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch |
BasePipelineStep | list[BasePipelineStep]
|
The step(s) for the false branch. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The builder instance for chaining. |
then(branch)
Define the branch to execute when the condition is true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch |
BasePipelineStep | list[BasePipelineStep]
|
The step(s) for the true branch. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The builder instance for chaining. |