OT v0.1.0 OT.Text.Scanner

Enumerates over a pair of operations, yielding a full or partial component from each

Summary

Types

The input to the scanner—a tuple containing two operations

An operation’s next scanned full or partial component, and its resulting tail operation

A tuple representing the new head component and tail operation of the two operations being scanned over

A type which is not to be split when iterating

Functions

Given a pair of two operations, return the next two full or partial components where the second component potentially affects the first

Types

The input to the scanner—a tuple containing two operations

operation_split()
operation_split() :: {OT.Text.Component.t | nil, OT.Text.Operation.t}

An operation’s next scanned full or partial component, and its resulting tail operation

output()

A tuple representing the new head component and tail operation of the two operations being scanned over

skip_type()
skip_type() :: :delete | :insert | nil

A type which is not to be split when iterating

Functions

next(input, skip_type \\ nil)
next(input, skip_type) :: output

Given a pair of two operations, return the next two full or partial components where the second component potentially affects the first.

A third parameter may be passed that specifies that components of a given type are not to be split up: For example, when transforming operation a over operation b, the insert operations from a should not be split in order to preserve user intent.

When any operation’s componets are exhausted, it will be represented by the tuple {nil, []}.

Examples

iex> OT.Text.Scanner.next({[4, %{i: "Foo"}], [2]})
{{2, [2, %{i: "Foo"}]}, {2, []}}

iex> OT.Text.Scanner.next({[%{i: "Foo"}], [2]}, :insert)
{{%{i: "Foo"}, []}, {2, []}}

iex> OT.Text.Scanner.next({[%{d: "Foo"}], [2]})
{{%{d: "Fo"}, [%{d: "o"}]}, {2, []}}