capturegraph.procedures.toolkits.control_flow.switch_cases
#
Switch Cases Toolkit#
This module provides an easy way to branch procedure execution based on procedure values.
switch_case(case, cases, default)
#
Switch-case branching based on the value of a procedure.
This method allows branching execution based on the value produced by the procedure. It takes a dictionary mapping possible values to procedures to execute for each case, as well as a default procedure if no cases match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
Procedure[C]
|
The procedure whose output value is used for branching |
required |
cases
|
dict[Procedure[C], Procedure[R]]
|
Mapping of case values to procedures |
required |
default
|
Procedure[R]
|
Procedure to execute if no cases match |
required |
Returns:
| Type | Description |
|---|---|
Procedure[R]
|
Procedure[R]: The procedure corresponding to the matched case or default |
Source code in capturegraph-lib/capturegraph/procedures/toolkits/control_flow/switch_cases.py
switch_case_strings(case, cases, default)
#
Switch-case branching based on the string value of a procedure.
Similar to switch_case, but specifically for string values. It allows branching execution based on the string output of the procedure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
Procedure[PString]
|
The procedure whose string output is used for branching |
required |
cases
|
dict[str, Procedure[R]]
|
Mapping of string case values to procedures |
required |
default
|
Procedure[R]
|
Procedure to execute if no cases match |
required |
Returns:
| Type | Description |
|---|---|
Procedure[R]
|
Procedure[R]: The procedure corresponding to the matched case or default |