Choice RulesΒΆ
This module defines the choice rules for a Choice state.
Use the add_choice()
method to add a branch to a Choice step.
my_choice_state.add_choice(
rule=ChoiceRule.BooleanEquals(variable=previous_state.output()["Success"], value=True),
next_step=happy_path
)
my_choice_state.add_choice(
ChoiceRule.BooleanEquals(variable=previous_state.output()["Success"], value=False),
next_step=sad_state
)
In this example, choice rules are added to the Choice state
my_choice_state
using add_choice()
.
Logic in a Choice state
is implemented with the help of Choice Rules. A Choice Rule encapsulates a
comparison, which contains the following:
- An input variable to compare
- The type of comparison
- The value to compare the variable to
The type of comparison is abstracted by the classes provided in this module. Multiple choice rules can be
compounded together using the And()
or
Or()
classes. A choice rule can be negated using
the Not()
class.