LanguageExt.Core

LanguageExt.Core DataTypes Patch

Contents

class Edit <EqA, A> Source #

where EqA : struct, Eq<A>

Data type that represents an edit in a patch. Supports three sub-class 'cases':

Edit.Insert
Edit.Delete
Edit.Replace

These represent the total set of operations that can be represented in a Patch

Parameters

type EqA
type A

Fields

field int Position Source #

field A Element Source #

Methods

method Edit<EqA, A> MapOld (Func<A, A> f) Source #

Maps the outgoing value using the function provided. This has no effect on Insert

method Edit<EqA, A> MapNew (Func<A, A> f) Source #

Maps the new value using the function provided. This has no effect on Delete

method bool Equals (object obj) Source #

Equality operator

method int GetHashCode () Source #

Hash code provider

method bool Equals (Edit<EqA, A> other) Source #

Equality operator

Operators

operator == (Edit<EqA, A> a, Edit<EqA, A> b) Source #

Equality operator

operator != (Edit<EqA, A> a, Edit<EqA, A> b) Source #

Non-equality operator

class Insert Source #

Represents an Insert edit operation

Constructors

constructor Insert (int position, A element) Source #

Methods

method Insert New (int position, A element) Source #

method string ToString () Source #

method Edit<EqA, A> MapOld (Func<A, A> f) Source #

method Edit<EqA, A> MapNew (Func<A, A> f) Source #

method bool Equals (Insert other) Source #

method bool Equals (object obj) Source #

method int GetHashCode () Source #

Operators

operator == (Insert a, Insert b) Source #

operator != (Insert a, Insert b) Source #

class Delete Source #

Represents an Delete edit operation

Constructors

constructor Delete (int position, A element) Source #

Methods

method Delete New (int position, A element) Source #

method string ToString () Source #

method Edit<EqA, A> MapOld (Func<A, A> f) Source #

method Edit<EqA, A> MapNew (Func<A, A> f) Source #

method bool Equals (Delete other) Source #

method bool Equals (object obj) Source #

method int GetHashCode () Source #

Operators

operator == (Delete a, Delete b) Source #

operator != (Delete a, Delete b) Source #

class Replace Source #

Represents an Replace edit operation

Fields

Constructors

constructor Replace (int position, A element, A replaceElement) Source #

Methods

method Replace New (int position, A element, A replaceElement) Source #

method string ToString () Source #

method Edit<EqA, A> MapOld (Func<A, A> f) Source #

method Edit<EqA, A> MapNew (Func<A, A> f) Source #

method bool Equals (Replace other) Source #

method bool Equals (object obj) Source #

method int GetHashCode () Source #

Operators

operator == (Replace a, Replace b) Source #

operator != (Replace a, Replace b) Source #

struct Patch <EqA, A> Source #

where EqA : struct, Eq<A>

Fields

field Seq<Edit<EqA, A>> Edits Source #

Edits that represent the operations to perform on a document to transform it.

Methods

method bool Equals (Patch<EqA, A> mb) Source #

Equality operator

method bool Equals (object obj) Source #

Equality operator

method int GetHashCode () Source #

Hash code provider

method string ToString () Source #

Return a string representation of the patch

method bool Applicable (IEnumerable<A> document) Source #

Returns true if a patch can be safely applied to a document, that is, applicable(p, d) holds when d is a valid source document for the patch p.

method Patch<EqA, A> Append (Patch<EqA, A> mb) Source #

Monoid append: produces a patch is a merged version of this and the provided patch.

method Patch<EqA, A> Inverse () Source #

Compute the inverse of a patch

method int SizeChange () Source #

Returns the delta of the document's size when a patch is applied. Essentially the number of Insert minus the number of Delete

method IEnumerable<A> Apply (IEnumerable<A> va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (Seq<A> va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (Lst<A> va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (SpanArray<A> va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (Arr<A> va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (A[] va) Source #

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> Apply (List<A> va) Source #

Apply a patch to a document, returning the transformed document.

Operators

operator == (Patch<EqA, A> pa, Patch<EqA, A> pb) Source #

Equality operator

operator != (Patch<EqA, A> pa, Patch<EqA, A> pb) Source #

Non-equality operator

operator + (Patch<EqA, A> pa, Patch<EqA, A> pb) Source #

Patch summing operator: monoid append

operator - (Patch<EqA, A> pa) Source #

Patch inverse operator

class Patch Source #

Methods

method Patch<EqA, A> unsafeFromSeq <EqA, A> (Seq<Edit<EqA, A>> edits) Source #

where EqA : struct, Eq<A>

Convert a list of edits to a patch, making sure to eliminate conflicting edits and sorting by index.

method Patch<EqA, A> fromSeq <EqA, A> (Seq<Edit<EqA, A>> edits) Source #

where EqA : struct, Eq<A>

Convert a list of edits to a patch, making sure to eliminate conflicting edits and sorting by index.

method Patch<EqA, A> append <EqA, A> (Patch<EqA, A> px, Patch<EqA, A> py) Source #

where EqA : struct, Eq<A>

Monoid append: produces a patch is a merged version of both provided patches.

method Patch<EqA, A> inverse <EqA, A> (Patch<EqA, A> patch) Source #

where EqA : struct, Eq<A>

Compute the inverse of a patch

method bool applicable <EqA, A> (Patch<EqA, A> pa, IEnumerable<A> va) Source #

where EqA : struct, Eq<A>

Returns true if a patch can be safely applied to a document, that is, applicable(p, d) holds when d is a valid source document for the patch p.

method bool composable <EqA, A> (Patch<EqA, A> pa, Patch<EqA, A> pb) Source #

where EqA : struct, Eq<A>

Returns true if a patch can be validly composed with another. That is, composable(p, q) holds if q can be validly applied after p.

method int sizeChange <EqA, A> (Patch<EqA, A> patch) Source #

where EqA : struct, Eq<A>

Returns the delta of the document's size when a patch is applied. Essentially the number of Insert minus the number of Delete.

method Lst<A> apply <EqA, A> (Patch<EqA, A> patch, Lst<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method Seq<A> apply <EqA, A> (Patch<EqA, A> patch, Seq<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method Arr<A> apply <EqA, A> (Patch<EqA, A> patch, Arr<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method A[] apply <EqA, A> (Patch<EqA, A> patch, A[] va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method SpanArray<A> apply <EqA, A> (Patch<EqA, A> patch, SpanArray<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method List<A> apply <EqA, A> (Patch<EqA, A> patch, List<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method IEnumerable<A> apply <EqA, A> (Patch<EqA, A> patch, IEnumerable<A> va) Source #

where EqA : struct, Eq<A>

Apply a patch to a document, returning the transformed document.

method Patch<EqA, A> empty <EqA, A> () Source #

where EqA : struct, Eq<A>

Empty patch

method A ours <A> (A x, A y) Source #

Resolve a conflict by always using the left-hand side

method A theirs <A> (A x, A y) Source #

Resolve a conflict by always using the right-hand side

method (Patch<MonoidEqA, A> a, Patch<MonoidEqA, A> b) transform <MonoidEqA, A> (Patch<MonoidEqA, A> p, Patch<MonoidEqA, A> q) Source #

where MonoidEqA : struct, Monoid<A>, Eq<A>

A convenience version of transformWith which resolves conflicts using append.

method (Patch<EqA, A> a, Patch<EqA, A> b) transformWith <EqA, A> (Func<A, A, A> conflict, Patch<EqA, A> p, Patch<EqA, A> q) Source #

where EqA : struct, Eq<A>

Given two diverging patches p and q, transform(m, p, q) returns a pair of updated patches (np, nq) such that append(q, np) and append(p, nq) are equivalent patches that incorporate the changes of both p and q, up to merge conflicts, which are handled by the provided function m.

This is the standard transform function of Operational Transformation patch resolution techniques, and can be thought of as the pushout of two diverging patches within the patch groupoid.

method Patch<EqA, A> diff <EqA, A> (IEnumerable<A> va, IEnumerable<A> vb) Source #

where EqA : struct, Eq<A>

Compute the difference between two documents, using the Wagner-Fischer algorithm. O(mn) time and space.

apply(diff(d,e), d) == e

diff(d, d) == Patch.empty

apply(diff(d, e), d) == apply(inverse(diff(e, d)), d)

apply(append(diff(a, b), diff(b, c), a) == apply(diff(a, c), a)

applicable(diff(a, b) a)