Documentation

Batteries.Data.DList.Basic

structure Batteries.DList (α : Type u) :

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 push operations on lists, making it useful for append-heavy uses such as logging and pretty printing.

def Batteries.DList.ofList {α : Type u} (l : List α) :

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

Equations

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

Equations
def Batteries.DList.toList {α : Type u} :
DList αList α

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

Equations
  • { apply := f, invariant := invariant }.toList = f []
def Batteries.DList.singleton {α : Type u} (a : α) :

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

Equations
def Batteries.DList.cons {α : Type u} :
αDList αDList α

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

Equations
def Batteries.DList.append {α : Type u} :
DList αDList αDList α

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

Equations
  • { apply := f, invariant := h₁ }.append { apply := g, invariant := h₂ } = { apply := f g, invariant := }
def Batteries.DList.push {α : Type u} :
DList ααDList α

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

Equations
  • { apply := f, invariant := h }.push x✝ = { apply := fun (t : List α) => f (x✝ :: t), invariant := }
def Batteries.DList.ofThunk {α : Type u} (l : Thunk (List α)) :

Convert a lazily-evaluated List to a DList

Equations
@[deprecated Batteries.DList.ofThunk (since := "2024-10-16")]
def Batteries.DList.lazy_ofList {α : Type u} (l : Thunk (List α)) :

Alias of Batteries.DList.ofThunk.


Convert a lazily-evaluated List to a DList

Equations
def Batteries.DList.join {α : Type u_1} :
List (DList α)DList α

Concatenates a list of difference lists to form a single difference list. Similar to List.join.

Equations