Module

Data.CatList

Package
catenable-lists
Repository
purescript/purescript-catenable-lists

This module defines a strict catenable list.

The implementation is based on a queue where all operations require O(1) amortized time.

However, any single uncons operation may run in O(n) time.

See Purely Functional Data Structures (Okasaki 1996)

#CatList Source

data CatList a

A strict catenable list.

CatList may be empty, represented by CatNil.

CatList may be non-empty, represented by CatCons. The CatCons data constructor takes the first element of the list and a queue of CatList.

Constructors

Instances

#empty Source

empty :: forall a. CatList a

Create an empty catenable list.

Running time: O(1)

#null Source

null :: forall a. CatList a -> Boolean

Test whether a catenable list is empty.

Running time: O(1)

#singleton Source

singleton :: forall a. a -> CatList a

Create a catenable list with a single item.

Running time: O(1)

#length Source

length :: forall a. CatList a -> Int

Number of elements in queue.

Running time: O(n) in length of queue.

#append Source

append :: forall a. CatList a -> CatList a -> CatList a

Append all elements of a catenable list to the end of another catenable list, create a new catenable list.

Running time: O(1)

#cons Source

cons :: forall a. a -> CatList a -> CatList a

Append an element to the beginning of the catenable list, creating a new catenable list.

Running time: O(1)

#snoc Source

snoc :: forall a. CatList a -> a -> CatList a

Append an element to the end of the catenable list, creating a new catenable list.

Running time: O(1)

#uncons Source

uncons :: forall a. CatList a -> Maybe (Tuple a (CatList a))

Decompose a catenable list into a Tuple of the first element and the rest of the catenable list.

Running time: O(1)

Note that any single operation may run in O(n).

#fromFoldable Source

fromFoldable :: forall f. Foldable f => f ~> CatList

Convert any Foldable into a CatList.

Running time: O(n)