merge

fun <Value> merge(property: KProperty1<State, Value>, combine: (current: Value, changed: List<Value>) -> Value, write: State.(Value) -> State)

property gets what combine makes of the values of the nodes that changed it:

merge(Research::score, combine = { _, changed -> changed.max() }) { copy(score = it) }
merge(Research::status, combine = { _, changed -> changed.last() }) { copy(status = it) } // the last node wins

Parameters

combine

receives the value before the step and the values that differ from it, in the order of the nodes in the step. It is not called when no node changed the property.

write

returns the state with property set to the combined value.