| Safe Haskell | None |
|---|
Data.NonEmpty
- data T f a = Cons {}
- (!:) :: a -> f a -> T f a
- force :: T f a -> T f a
- apply :: (Applicative f, Cons f, Append f) => T f (a -> b) -> T f a -> T f b
- bind :: (Monad f, Cons f, Append f) => T f a -> (a -> T f b) -> T f b
- toList :: Foldable f => T f a -> [a]
- flatten :: Cons f => T f a -> f a
- fetch :: View f => f a -> Maybe (T f a)
- cons :: Cons f => a -> T f a -> T f a
- singleton :: Empty f => a -> T f a
- reverse :: (Traversable f, Reverse f) => T f a -> T f a
- mapHead :: (a -> a) -> T f a -> T f a
- mapTail :: (f a -> g a) -> T f a -> T g a
- init :: (Zip f, Cons f) => T f a -> f a
- last :: Foldable f => T f a -> a
- foldl1 :: Foldable f => (a -> a -> a) -> T f a -> a
- maximum :: (Ord a, Foldable f) => T f a -> a
- maximumBy :: Foldable f => (a -> a -> Ordering) -> T f a -> a
- maximumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> a
- minimum :: (Ord a, Foldable f) => T f a -> a
- minimumBy :: Foldable f => (a -> a -> Ordering) -> T f a -> a
- minimumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> a
- sum :: (Num a, Foldable f) => T f a -> a
- product :: (Num a, Foldable f) => T f a -> a
- append :: (Cons f, Append f) => T f a -> T f a -> T f a
- appendLeft :: (Append f, View f, Cons f) => f a -> T f a -> T f a
- appendRight :: Append f => T f a -> f a -> T f a
- cycle :: (Cons f, Append f) => T f a -> T f a
- zipWith :: Zip f => (a -> b -> c) -> T f a -> T f b -> T f c
- mapAdjacent :: Traversable f => (a -> a -> b) -> T f a -> f b
- sortBy :: (Sort f, Insert f) => (a -> a -> Ordering) -> T f a -> T f a
- sort :: (Ord a, Sort f, Insert f) => T f a -> T f a
- class Insert f where
- insert :: (Ord a, Insert f, Sort f) => a -> f a -> T f a
- scanl :: Traversable f => (b -> a -> b) -> b -> f a -> T f b
- scanr :: Traversable f => (a -> b -> b) -> b -> f a -> T f b
- transposeClip :: (Traversable f, Zip g, Repeat g) => f (g a) -> g (f a)
- class Tails f where
- class Functor f => RemoveEach f where
- removeEach :: T f a -> T f (a, f a)
Documentation
The type T can be used for many kinds of list-like structures with restrictions on the size.
-
T [] ais a lazy list containing at least one element. -
T (T []) ais a lazy list containing at least two elements. -
T Vector ais 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 ais a list that contains one or two elements. -
Maybeis isomorphic toOptional Empty. -
T Empty ais a list that contains exactly one element. -
T (T Empty) ais a list that contains exactly two elements. -
Optional (T Empty) ais a list that contains zero or two elements. - You can create a list type for every finite set of allowed list length by nesting Optional and NonEmpty constructors. If list length
nis allowed, then placeOptionalat depthn, if it is disallowed then placeNonEmpty. The maximm length is marked byEmpty.
Instances
| (Monad f, Empty f, Cons f, Append f) => Monad (T f) | |
| Functor f => Functor (T f) | |
| (Applicative f, Empty f, Cons f, Append f) => Applicative (T f) | |
| Foldable f => Foldable (T f) | |
| Traversable f => Traversable (T f) | |
| Show f => Show (T f) | |
| (Traversable f, Reverse f) => Reverse (T f) | |
| (Sort f, Insert f) => Sort (T f) | |
| Repeat f => Repeat (T f) | |
| Zip f => Zip (T f) | |
| (Cons f, Append f) => Append (T f) | |
| Empty f => Singleton (T f) | |
| Cons f => Cons (T f) | |
| Tails f => Tails (T f) | |
| RemoveEach f => RemoveEach (T f) | |
| Insert f => Insert (T f) | |
| (Eq a, Eq (f a)) => Eq (T f a) | |
| (Ord a, Ord (f a)) => Ord (T f a) | |
| (Show f, Show a) => Show (T f a) | |
| (Arbitrary a, Arbitrary f) => Arbitrary (T f a) |
maximumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> aSource
maximumKey is a total function
minimumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> aSource
minimumKey is a total function
appendRight :: Append f => T f a -> f a -> T f aSource
cycle :: (Cons f, Append f) => T f a -> T f aSource
generic variants: cycle or better Semigroup.cycle
mapAdjacent :: Traversable f => (a -> a -> b) -> T f a -> f bSource
sortBy :: (Sort f, Insert 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).
insert :: (Ord a, Insert f, Sort f) => a -> f a -> T f aSource
Insert an element into an ordered list while preserving the order. The first element of the resulting list is returned individually. We need this for construction of a non-empty list.
scanl :: Traversable f => (b -> a -> b) -> b -> f a -> T f bSource
scanr :: Traversable f => (a -> b -> b) -> b -> f a -> T f bSource
transposeClip :: (Traversable f, Zip g, Repeat g) => f (g a) -> g (f a)Source
Always returns a rectangular list by clipping all dimensions to the shortest slice. Be aware that transpose [] == repeat [].
class Functor f => RemoveEach f whereSource
Methods
removeEach :: T f a -> T f (a, f a)Source
Instances
| RemoveEach [] | |
| RemoveEach Maybe | |
| RemoveEach T | |
| RemoveEach f => RemoveEach (T f) | |
| RemoveEach f => RemoveEach (T f) |