ActionBranchConfiguration

@MainActor
public struct ActionBranchConfiguration<InteractorType, ContentType> : ActionConfiguring where InteractorType : InteractorTypeable, ContentType : ContentTypeable

A configuration object that defines an ActionBranch step for use within an ActionSequenceConfiguration.

Build a branch by chaining .branch(when:action:transformer:) calls, then optionally adding .otherwise(action:transformer:) as a fallback that runs when no condition matches. This object evaluates branch path conditions in declaration order at runtime and runs the first matching path. Each path can carry an optional transformer that converts its output before the branch forwards it through the shared output conduit (assigned by ActionSequenceConfiguration‘s .output() method).

let config = try ActionSequenceConfiguration<InteractorType, ContentType>()
    .step(
        ActionBranchConfiguration<InteractorType, ContentType>()
            .branch(when: HasImagesCondition(), action: processImageStep, transformer: ImageToFileTransformer())
            .branch(when: HasTextCondition(), action: processTextStep)
            .otherwise(defaultStep)
    )
    .output()
    .step(nextStep)

Note

ActionBranchConfiguration is value-typed; each chained call returns a modified copy.
  • A placeholder action type satisfying the ActionConfiguring requirement. A branch has no single interactor action of its own.

    See more

    Declaration

    Swift

    public enum ActionBranchType : InteractorRequestActionTypeable
  • Undocumented

    Declaration

    Swift

    public typealias ActionType = ActionBranchType
  • Declaration

    Swift

    @MainActor
    public let actionType: ActionBranchType
  • Unused; a branch aggregates multiple child actions and has no single assistant of its own.

    Declaration

    Swift

    @MainActor
    public let assistant: InteractorAssistantType
  • Undocumented

    Declaration

    Swift

    @MainActor
    public let configurationType: ActionConfigurationType
  • The output conduit assigned by ActionSequenceConfiguration‘s .conduit() method, forwarding the selected path’s output to the next sequence step.

    Declaration

    Swift

    @MainActor
    public var outputConduit: (any ActionSequenceConduiting<ContentType>)?
  • Declaration

    Swift

    @MainActor
    public let identifier: (any ActionIdentifying)?
  • Declaration

    Swift

    @MainActor
    public let shouldEndParentTaskOnFailure: Bool
  • Declaration

    Swift

    @MainActor
    public let shouldSaveResult: Bool
  • The ordered list of branch path configurations. Conditions are evaluated in declaration order; the first match is selected.

    Declaration

    Swift

    @MainActor
    public private(set) var cases: [ActionBranchPathConfiguration<InteractorType, ContentType>] { get }
  • Undocumented

    Declaration

    Swift

    @MainActor
    public init(identifier: (any ActionIdentifying)? = nil, shouldEndParentTaskOnFailure: Bool = false, shouldSaveResult: Bool = true)
  • Appends a conditional branch path.

    Declaration

    Swift

    @MainActor
    public func branch(when condition: any BranchConditionable<ContentType>, action: any ActionConfiguring<InteractorType, ContentType>, transformer: (any ContentTransformable<ContentType, ContentType>)? = nil) -> ActionBranchConfiguration<InteractorType, ContentType>

    Parameters

    condition

    The BranchCondition evaluated at runtime to determine whether this path is selected.

    action

    The action configuration to build and run when this branch path is selected.

    transformer

    An optional transformer applied to the branch path’s output before forwarding downstream. Required when the path’s output shape differs from what the downstream step expects.

    Return Value

    A copy of this configuration with the branch path appended.

  • Appends an unconditional fallback branch path that runs when no earlier condition matches.

    Declaration

    Swift

    @MainActor
    public func otherwise(_ action: any ActionConfiguring<InteractorType, ContentType>, transformer: (any ContentTransformable<ContentType, ContentType>)? = nil) -> ActionBranchConfiguration<InteractorType, ContentType>

    Parameters

    action

    The action configuration to build and run as the fallback.

    transformer

    An optional transformer applied to the fallback branch path’s output before forwarding downstream.

    Return Value

    A copy of this configuration with the fallback branch path appended.

  • Appends an unconditional fallback branch path backed by a built-in result-handling behavior.

    Use .skip to complete silently when no earlier condition matched, or .fail to stop the sequence and return a Result .failure with the accumulated partial results.

    Declaration

    Swift

    @MainActor
    public func otherwise(_ resultHandling: BranchResultHandlingType) -> ActionBranchConfiguration<InteractorType, ContentType>

    Parameters

    resultHandling

    The built-in behavior to apply as the fallback.

    Return Value

    A copy of this configuration with the fallback branch path appended.

  • Declaration

    Swift

    @MainActor
    public func buildAssistant() throws -> any AsyncInteractorAssisting<InteractorType, ContentType>
  • Builds the ActionBranch by constructing a BranchConditionable object for each branch path configuration.

    Declaration

    Swift

    @MainActor
    public func buildAction(resultHandler: any InteractorResultHandling<InteractorType, ContentType>) throws -> any ActionPerformable<ContentType>