text_delta v1.2.0 TextDelta.Composition
The composition of two non-concurrent deltas into a single delta.
The deltas are composed in such a way that the resulting delta has the same effect on text state as applying one delta and then the other:
S ○ compose(Oa, Ob) = S ○ Oa ○ Ob
In more simple terms, composition allows you to take many deltas and transform them into one of equal effect. When used together with Operational Transformation that allows to reduce system overhead when tracking non-synced changes.
Summary
Functions
Composes two deltas into a single equivalent delta
Functions
Composes two deltas into a single equivalent delta.
Example
iex> foo = TextDelta.insert(TextDelta.new(), "Foo")
%TextDelta{ops: [%{insert: "Foo"}]}
iex> bar = TextDelta.insert(TextDelta.new(), "Bar")
%TextDelta{ops: [%{insert: "Bar"}]}
iex> TextDelta.compose(bar, foo)
%TextDelta{ops: [%{insert: "FooBar"}]}