NonEmptyList-0.0.3: A list with a length of at least one.

Data.List.NonEmpty

Contents

Description

A type-safe list that has at least one element.

Synopsis

Documentation

data NonEmpty a Source

An list with at least one element.

Accessors

neHead :: NonEmpty a -> aSource

The head of the non-empty list.

neTail :: NonEmpty a -> [a]Source

The tail of the non-empty list.

fromNonEmpty :: NonEmpty a -> [a]Source

Conversion to ordinary list (like Data.Foldable.toList, but O(1)).

Constructors

nonEmptySource

Arguments

:: a

The head.

-> [a]

The tail.

-> NonEmpty a 

Constructs a non-empty list with the given head and tail.

(|:)Source

Arguments

:: a

The head.

-> [a]

The tail.

-> NonEmpty a 

Constructs a non-empty list with the given head and tail (an alias for nonEmpty).

toNonEmptySource

Arguments

:: [a]

The list to convert.

-> Maybe (NonEmpty a) 

Tries to convert a list to a NonEmpty returning Nothing if the given list is empty.

unsafeToNonEmptySource

Arguments

:: [a]

The list to convert (must not be empty).

-> NonEmpty a 

WARNING: Fails if given the empty list. Tries to convert a list to a NonEmpty.

(.:)Source

Arguments

:: a

The value to prepend.

-> NonEmpty a

The non-empty list to prepend to.

-> NonEmpty a 

Prepends a value to a non-empty list.

(.++)Source

Arguments

:: NonEmpty a

The non-empty list to prepend.

-> NonEmpty a

The non-empty list to prepend to.

-> NonEmpty a 

Prepends a non-empty list to another non-empty list.

List functions

reverse :: NonEmpty a -> NonEmpty aSource

Reverses the elements of the (finite) non-empty list.

scanl :: (b -> a -> b) -> b -> NonEmpty a -> NonEmpty bSource

scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty aSource

scanr :: (a -> b -> b) -> b -> NonEmpty a -> NonEmpty bSource

scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty aSource

iterate :: (a -> a) -> a -> NonEmpty aSource

cycle :: Foldable f => f a -> NonEmpty aSource

inits :: [a] -> NonEmpty [a]Source

tails :: [a] -> NonEmpty [a]Source

insert :: Ord a => a -> NonEmpty a -> NonEmpty aSource

Tests