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.
- apply : List α → List α
"Run" a
DListby appending it on the right by aList αto get anotherList α.
Instances For
O(1) (apply is O(|l|)). Convert a List α into a DList α.
Equations
- Batteries.DList.ofList l = { apply := fun (x : List α) => l ++ x, invariant := ⋯ }
Instances For
O(1) (apply is O(1)). Return an empty DList α.
Equations
- Batteries.DList.empty = { apply := id, invariant := ⋯ }
Instances For
@[implicit_reducible]
Equations
- Batteries.DList.instEmptyCollection = { emptyCollection := Batteries.DList.empty }
@[implicit_reducible]
Equations
- Batteries.DList.instInhabited = { default := Batteries.DList.empty }
O(1) (apply is O(1)). A DList α corresponding to the list [a].
Equations
- Batteries.DList.singleton a = { apply := fun (t : List α) => a :: t, invariant := ⋯ }
Instances For
@[implicit_reducible]
Equations
- Batteries.DList.instAppend = { append := Batteries.DList.append }
Convert a lazily-evaluated List to a DList
Equations
- Batteries.DList.ofThunk l = { apply := fun (xs : List α) => l.get ++ xs, invariant := ⋯ }
Instances For
Concatenates a list of difference lists to form a single difference list. Similar to
List.join.
Equations
- Batteries.DList.join [] = Batteries.DList.empty
- Batteries.DList.join (x_1 :: xs) = x_1 ++ Batteries.DList.join xs