non-empty-0.0: List-like structures with static checks on the number of elements

Safe Haskell None

Data.NonEmpty

Synopsis

# Documentation

data T f a Source

The type `T` can be used for many kinds of list-like structures with restrictions on the size.

• `T [] a` is a lazy list containing at least one element.
• `T (T []) a` is a lazy list containing at least two elements.
• `T Vector a` is a vector with at least one element. You may also use unboxed vectors but the first element will be stored in a box and you will not be able to use many functions from this module.
• `T Maybe a` is a list that contains one or two elements.
• `T Empty a` is a list that contains exactly one element.
• `T (T Empty) a` is a list that contains exactly two elements.

Constructors

 Cons Fieldshead :: a tail :: f a

Instances

 (Monad f, Empty f, Cons f, Append f) => Monad (T f) Functor f => Functor (T f) (Functor (T f), Applicative f, Empty f, Cons f, Append f) => Applicative (T f) Foldable f => Foldable (T f) (Functor (T f), Foldable (T f), Traversable f) => Traversable (T f) Sort f => Sort (T f) Zip f => Zip (T f) (Cons f, Append f) => Append (T f) Empty f => Singleton (T f) Cons f => Cons (T f) (Eq a, Eq (f a)) => Eq (T f a) (Eq (T f a), Ord a, Ord (f a)) => Ord (T f a) (Show a, Show (f a)) => Show (T f a) (Arbitrary a, Arbitrary f) => Arbitrary (T f a)

(!:) :: a -> f a -> T f aSource

force :: T f a -> T f aSource

Force immediate generation of Cons.

apply :: (Applicative f, Cons f, Append f) => T f (a -> b) -> T f a -> T f bSource

Implementation of `<*>` without the `Empty` constraint that is needed for `pure`.

bind :: (Monad f, Cons f, Append f) => T f a -> (a -> T f b) -> T f bSource

Implementation of `>>=` without the `Empty` constraint that is needed for `return`.

data Empty a Source

Constructors

 Empty

Instances

 Functor Empty Foldable Empty Traversable Empty View Empty Empty Empty Eq (Empty a) Eq (Empty a) => Ord (Empty a) Show (Empty a) Arbitrary (Empty a)

toList :: Foldable f => T f a -> [a]Source

flatten :: Cons f => T f a -> f aSource

fetch :: View f => f a -> Maybe (T f a)Source

cons :: Cons f => a -> T f a -> T f aSource

singleton :: Empty f => a -> T f aSource

reverse :: (Foldable f, Cons f, Empty f) => T f a -> T f aSource

mapHead :: (a -> a) -> T f a -> T f aSource

mapTail :: (f a -> g a) -> T f a -> T g aSource

init :: (Zip f, Cons f) => T f a -> f aSource

last :: Foldable f => T f a -> aSource

foldl1 :: Foldable f => (a -> a -> a) -> T f a -> aSource

maximum :: (Ord a, Foldable f) => T f a -> aSource

maximum is a total function

minimum :: (Ord a, Foldable f) => T f a -> aSource

minimum is a total function

sum :: (Num a, Foldable f) => T f a -> aSource

sum does not need a zero for initialization

product :: (Num a, Foldable f) => T f a -> aSource

product does not need a one for initialization

append :: (Cons f, Append f) => T f a -> T f a -> T f aSource

cycle :: (Cons f, Append f) => T f a -> T f aSource

zipWith :: Zip f => (a -> b -> c) -> T f a -> T f b -> T f cSource

sortBy :: Sort f => (a -> a -> Ordering) -> T f a -> T f aSource

If you nest too many non-empty lists then the efficient merge-sort (linear-logarithmic runtime) will degenerate to an inefficient insert-sort (quadratic runtime).

sort :: (Ord a, Sort f) => T f a -> T f aSource

insertBy :: (Sort f, Cons f) => (a -> a -> Ordering) -> a -> T f a -> T f aSource

insert :: (Ord a, Sort f, Cons f) => a -> T f a -> T f aSource