# Documentation

Std.Data.DList

structure Std.DList (α : Type u) :
• "Run" a DList by appending it on the right by a List α to get another List α.

apply : List αList α
• The apply function of a DList is completely determined by the list apply [].

invariant : ∀ (l : List α), apply l = apply [] ++ l

A difference List is a Function that, given a List, returns the original contents of the difference List prepended to the given List. This structure supports O(1) append and concat operations on lists, making it useful for append-heavy uses such as logging and pretty printing.

Instances For
def Std.DList.ofList {α : Type u} (l : List α) :

O(1) (apply is O(|l|)). Convert a List α into a DList α.

Equations
• = { apply := fun x => l ++ x, invariant := (_ : ∀ (t : List α), l ++ t = l ++ [] ++ t) }
def Std.DList.empty {α : Type u} :

O(1) (apply is O(1)). Return an empty DList α.

Equations
• Std.DList.empty = { apply := id, invariant := (_ : ∀ (x : List α), id x = id x) }
Equations
• Std.DList.instEmptyCollectionDList = { emptyCollection := Std.DList.empty }
def Std.DList.toList {α : Type u} :
List α

O(apply()). Convert a DList α into a List α by running the apply function.

Equations
• = match x with | { apply := f, invariant := invariant } => f []
def Std.DList.singleton {α : Type u} (a : α) :

O(1) (apply is O(1)). A DList α corresponding to the list [a].

Equations
• = { apply := fun t => a :: t, invariant := (_ : ∀ (x : List α), (fun t => a :: t) x = (fun t => a :: t) x) }
def Std.DList.cons {α : Type u} :
α

O(1) (apply is O(1)). Prepend a on a DList α.

Equations
• One or more equations did not get rendered due to their size.
def Std.DList.append {α : Type u} :

O(1) (apply is O(1)). Append two DList α.

Equations
• = match x, x with | { apply := f, invariant := h₁ }, { apply := g, invariant := h₂ } => { apply := f g, invariant := (_ : ∀ (t : List α), f (g t) = f (g []) ++ t) }
def Std.DList.push {α : Type u} :
α

O(1) (apply is O(1)). Append an element at the end of a DList α.

Equations
• = match x, x with | { apply := f, invariant := h }, a => { apply := fun t => f (a :: t), invariant := (_ : ∀ (t : List α), f (a :: t) = f [a] ++ t) }
instance Std.DList.instAppendDList {α : Type u} :
Equations
• Std.DList.instAppendDList = { append := Std.DList.append }