collapse

Function collapse 

Source
pub fn collapse(ops: &mut Vec<PlanOp>)
Expand description

Drop every removal of an element that is also added in the same transition.

One pass, three jobs, because in all three the right answer is the same: an element that has an Add somewhere still exists, so the Remove is wrong. A full AddUser/CreateChannel carries the complete state, and the client merges UserState/ChannelState rather than replacing, so re-sending the element whole simply updates it.

situationoperations producedafter collapse
the element changes scopeRemove(old) + Add(new)Add alone
vanish to unvanishRemove(overlay) + Add(shared)Add alone, it changes channel
unvanish to vanishRemove(shared) + Add(overlay)Add alone
dropped from the overlay, absent from the shared viewRemove aloneRemove kept
gone everywhereRemove aloneRemove kept

Three problems that looked distinct, one function: that is the sign it sits at the right level.