reverse-list-0.2.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.List.Cons

Description

This module exists primarily for symmetry with Data.List.Snoc However, it can also be used in place of the Prelude list type:

This module only exports functions that are efficient on linked lists. Many functions on that type (last isSuffixOf) though technically implementable, do not represent the intended use of a linked list in terms of performance.

Additionally, this module does not export any partial functions: head and tail return their results under a Maybe.

Synopsis

Documentation

type List = [] Source #

As a counterpart to RList/Tsil.

pattern Nil :: List a Source #

An empty List, such as nil.

pattern Cons :: a -> List a -> List a Source #

The List consisting of head and tail elements, such as created by cons.

nil :: List a Source #

The empty List.

cons :: a -> List a -> List a Source #

O(1) Append an element.

If you are looking for snoc, you should use an RList, or a finite sequence/queue type.

uncons :: List a -> Maybe (a, List a) Source #

O(1) Access the first element and trailing portion of the list. See also head and tail if you only need one component.

If you are looking for unsnoc, you should use an RList, or a finite sequence/queue type.

singleton :: a -> List a Source #

Create a single-element List.

head :: List a -> Maybe a Source #

O(1) extract the first element of a list, if it exists. See also uncons if you also need tail at the same time.

tail :: List a -> Maybe (List a) Source #

O(1) extract the elements of a list other than the last, if they exist. See also uncons if you also need head at the same time.