conditionalEdge

fun conditionalEdge(from: String, targets: Set<String>? = null, condition: EdgeCondition<State>)

Adds a conditional edge: after from finishes, condition picks the next node from the state.

Declare the possible targets whenever you can. They are checked when the graph is compiled, the value returned by condition is checked against them at run time, and they let compile detect unreachable nodes. With targets = null the condition may return any node name.

A node can have either one conditional edge or static edges, not both.


fun conditionalEdge(from: NodeRef, targets: Set<String>? = null, condition: EdgeCondition<State>)

Adds a conditional edge from the node referenced by from. See the overload taking a node name.


@JvmName(name = "conditionalEdgeToRefs")
fun conditionalEdge(from: NodeRef, targets: Set<NodeRef>, condition: suspend (State) -> NodeRef)

Adds a conditional edge that works with references instead of names: condition returns one of targets, so a misspelled node is a compiler error.

conditionalEdge(check, targets = setOf(write, NodeRef.END)) { draft ->
if (draft.isGood) NodeRef.END else write
}

To finish the branch, list NodeRef.END in targets and return it.


@JvmName(name = "conditionalEdgeToRefs")
fun conditionalEdge(from: String, targets: Set<NodeRef>, condition: suspend (State) -> NodeRef)

Adds a conditional edge that works with references, from the node named from, usually START. See the overload taking a node reference.