compile
Validates the graph and returns an executable CompiledGraph.
Give reducer or rules, not both. With rules, each node of a step gets the state from before the step, the update of a node with a work too, and the rules merge what all of them return, in the order the nodes were added to the graph. Two nodes that set a property to different values then fail the run as replace says, whatever form the nodes have:
val graph = StateGraph<Job> {
START then node("web", work = { searchWeb() }) { job, found -> job.copy(notes = job.notes + found) }
START then node("docs", work = { searchDocs() }) { job, found -> job.copy(notes = job.notes + found) }
}.compile(
rules = mergeRules {
append(Job::notes) { copy(notes = it) }
replace(Job::status) { copy(status = it) }
},
)MergeRules given as reducer work the same way as rules, so that the rules hold for both forms of node however they are given.
Without rules, the updates are applied one after another, each to the state that the update before it returned, and the node added later wins.
Parameters
merge the results of all nodes that ran in the same step, whatever form they have.
merges the states of nodes that ran in the same step and each returned a whole state, given in the order the nodes were added. Required when two such nodes can run in the same step, unless rules are given. Nodes added with a work and an update do not need it, unless it is a MergeRules, which then merges them too, as rules do. It comes last so that it can be written as a trailing lambda; give it by name otherwise.
Throws
listing every problem found in the graph definition.