league / difference-list / DList

A representation of lists with an efficient append operation.

This is particularly useful for efficient logging and pretty printing, where repeatedly appending lists quickly becomes too expensive. Internally, DList is a function that prepends elements to its parameter. Thus the append operation is just function composition. Ultimately, a DList is converted to a regular List by applying the function to the empty list.

Some limitations of the DList representation are:


type DList a

A difference list containing elements of type a.

toList : DList a -> List a

Convert to a regular Elm List by applying the underlying function representation.

Construction

empty : DList a

The empty list.

singleton : a -> DList a

Construct a list containing one element.

cons : a -> DList a -> DList a

Prepend an element onto the front of the list.

snoc : DList a -> a -> DList a

Add an element onto the back of the list. O(1) just like append.

append : DList a -> DList a -> DList a

Concatenate two lists.

fromList : List a -> DList a

Convert a regular Elm List to a difference list.

Processing

concat : List (DList a) -> DList a

Concatenate a list of difference lists.

foldr : (a -> b -> b) -> b -> DList a -> b

Iterate through a DList.

intersperse : DList a -> List (DList a) -> DList a

Intersperse the contents of a DList between other lists.

map : (a -> b) -> DList a -> DList b

Apply a function to each element, accumulating the results as a DList.