Safe Haskell | Trustworthy |
---|---|
Language | Haskell98 |
Synopsis
- data NonEmpty a
- pattern (:|) :: a -> [a] -> NonEmpty a
- singleton :: a -> NonEmpty a
- fromCons :: a -> [a] -> NonEmpty a
- aNonEmpty :: NonEmpty a -> NonEmpty a
- fromNonEmpty :: NonEmpty a -> NonEmpty a
- toNonEmpty :: NonEmpty a -> NonEmpty a
- fromList :: [a] -> Maybe (NonEmpty a)
- toList :: NonEmpty a -> [a]
- length :: NonEmpty a -> Int
- head :: NonEmpty a -> a
- tail :: NonEmpty a -> [a]
- last :: NonEmpty a -> a
- init :: NonEmpty a -> [a]
- cons :: a -> NonEmpty a -> NonEmpty a
- uncons :: NonEmpty a -> (a, [a])
- snoc :: NonEmpty a -> a -> NonEmpty a
- unsnoc :: forall a. NonEmpty a -> ([a], a)
- unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b
- sort :: forall a. Ord a => NonEmpty a -> NonEmpty a
- reverse :: NonEmpty a -> NonEmpty a
- inits :: Foldable f => f a -> NonEmpty [a]
- inits1 :: forall a. NonEmpty a -> NonEmpty (NonEmpty a)
- tails :: Foldable f => f a -> NonEmpty [a]
- tails1 :: forall a. NonEmpty a -> NonEmpty (NonEmpty a)
- append :: NonEmpty a -> NonEmpty a -> NonEmpty a
- appendList :: NonEmpty a -> [a] -> NonEmpty a
- prependList :: [a] -> NonEmpty a -> NonEmpty a
- map :: (a -> b) -> NonEmpty a -> NonEmpty b
- intersperse :: a -> NonEmpty a -> NonEmpty a
- foldl1 :: (a -> a -> a) -> NonEmpty a -> a
- foldl1' :: (a -> a -> a) -> NonEmpty a -> a
- foldr1 :: (a -> a -> a) -> NonEmpty a -> a
- scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b
- scanl' :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b
- scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b
- scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- transpose :: forall a. NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a)
- sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
- sortOn :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
- sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
- iterate :: (a -> a) -> a -> NonEmpty a
- repeat :: a -> NonEmpty a
- cycle :: NonEmpty a -> NonEmpty a
- insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a
- some1 :: Alternative f => f a -> f (NonEmpty a)
- take :: Int -> NonEmpty a -> [a]
- drop :: Int -> NonEmpty a -> [a]
- splitAt :: Int -> NonEmpty a -> ([a], [a])
- takeWhile :: (a -> Bool) -> NonEmpty a -> [a]
- dropWhile :: (a -> Bool) -> NonEmpty a -> [a]
- span :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- break :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- filter :: (a -> Bool) -> NonEmpty a -> [a]
- partition :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- group :: (Foldable f, Eq a) => f a -> [NonEmpty a]
- groupAll :: Ord a => [a] -> [NonEmpty a]
- groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a]
- groupAllBy :: (a -> a -> Ordering) -> [a] -> [NonEmpty a]
- groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a]
- groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a]
- group1 :: forall a. Eq a => NonEmpty a -> NonEmpty (NonEmpty a)
- groupAll1 :: Ord a => NonEmpty a -> [NonEmpty a]
- groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
- groupAllBy1 :: (a -> a -> Ordering) -> [a] -> [NonEmpty a]
- groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
- groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
- isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool
- nub :: Eq a => NonEmpty a -> NonEmpty a
- nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
- (!?) :: NonEmpty a -> Int -> Maybe a
- zip :: forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
- zipWith :: forall a b c. (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
Construction
A list with one or more elements.
Instances
MonadFix NonEmpty Source # | |
Defined in Data.List.NeoNonEmpty | |
MonadZip NonEmpty Source # | |
Foldable NonEmpty Source # | |
Defined in Data.List.NeoNonEmpty fold :: Monoid m => NonEmpty m -> m # foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m # foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m # foldr :: (a -> b -> b) -> b -> NonEmpty a -> b # foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b # foldl :: (b -> a -> b) -> b -> NonEmpty a -> b # foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b # foldr1 :: (a -> a -> a) -> NonEmpty a -> a # foldl1 :: (a -> a -> a) -> NonEmpty a -> a # elem :: Eq a => a -> NonEmpty a -> Bool # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # | |
Eq1 NonEmpty Source # | |
Ord1 NonEmpty Source # | |
Defined in Data.List.NeoNonEmpty | |
Read1 NonEmpty Source # | |
Defined in Data.List.NeoNonEmpty | |
Show1 NonEmpty Source # | |
Applicative NonEmpty Source # | |
Functor NonEmpty Source # | |
Monad NonEmpty Source # | |
Generic1 NonEmpty Source # | |
Data a => Data (NonEmpty a) Source # | |
Defined in Data.List.NeoNonEmpty gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonEmpty a -> c (NonEmpty a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonEmpty a) # toConstr :: NonEmpty a -> Constr # dataTypeOf :: NonEmpty a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonEmpty a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonEmpty a)) # gmapT :: (forall b. Data b => b -> b) -> NonEmpty a -> NonEmpty a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQ :: (forall d. Data d => d -> u) -> NonEmpty a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> NonEmpty a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # | |
Semigroup (NonEmpty a) Source # | |
Generic (NonEmpty a) Source # | |
IsList (NonEmpty a) Source # | |
Read a => Read (NonEmpty a) Source # | |
Show a => Show (NonEmpty a) Source # | |
Eq a => Eq (NonEmpty a) Source # | |
Ord a => Ord (NonEmpty a) Source # | |
type Rep1 NonEmpty Source # | |
Defined in Data.List.NeoNonEmpty | |
type Rep (NonEmpty a) Source # | |
Defined in Data.List.NeoNonEmpty | |
type Item (NonEmpty a) Source # | |
Defined in Data.List.NeoNonEmpty |
Type annotations
aNonEmpty :: NonEmpty a -> NonEmpty a Source #
A non empty thing. Useful as a syntactically lightweight type annotation, especially when using OverloadedLists:
>>>
:set -XOverloadedLists
>>>
[(), ()]
• Ambiguous type variable ‘a0’ arising from a use of ‘print’ prevents the constraint ‘(Show a0)’ from being solved.>>>
aNonEmpty [(), ()]
[(),()]
Converting to and from base's NonEmpty
Converting to and from lists
fromList :: [a] -> Maybe (NonEmpty a) Source #
Converts a normal list to a NonEmpty list, given the list has at least one element
Basic functions
init :: NonEmpty a -> [a] Source #
Extract everything except the last element of the nonempty stream.
uncons :: NonEmpty a -> (a, [a]) Source #
Produces the first element of the nonempty stream, and a stream of the remaining elements.
unsnoc :: forall a. NonEmpty a -> ([a], a) Source #
Produces all elements up to the last element, and the last element
inits :: Foldable f => f a -> NonEmpty [a] Source #
Produces all the prefixes of a stream, starting with the shortest.
The result is NonEmpty
because the result always contains the empty list as
the first element.
>>>
inits [1,2,3]
[[], [1], [1,2], [1,2,3]]
>>>
inits [1]
[[], [1]]
>>>
inits []
[[]]
inits1 :: forall a. NonEmpty a -> NonEmpty (NonEmpty a) Source #
Produces all the nonempty prefixes of a nonempty stream, starting with the shortest.
>>>
inits1 [1,2,3]
[[1], [1,2], [1,2,3]]
>>>
inits1 [1]
[[1]]
tails :: Foldable f => f a -> NonEmpty [a] Source #
Produces all the suffixes of a stream, starting with the longest.
The result is NonEmpty
because the result always contains the empty list as
the first element.
>>>
tails [1,2,3]
[[1, 2, 3], [2, 3], [3], []]
>>>
tails [1]
[[1], []]
>>>
tails []
[[]]
tails1 :: forall a. NonEmpty a -> NonEmpty (NonEmpty a) Source #
Produces all the nonempty suffixes of a nonempty stream, starting with the longest.
>>>
tails1 [1,2,3]
[[1, 2, 3], [2, 3], [3]]
>>>
tails1 [1]
[[1]]
append :: NonEmpty a -> NonEmpty a -> NonEmpty a Source #
A monomorphic version of <> for NonEmpty
.
>>>
append [1] [2, 3]
[1, 2, 3]
appendList :: NonEmpty a -> [a] -> NonEmpty a Source #
Append a list at the end of a NonEmpty
.
>>>
appendList [1, 2, 3] []
[1, 2, 3]
>>>
appendList [1, 2, 3] [4, 5]
[1, 2, 3, 4, 5]
prependList :: [a] -> NonEmpty a -> NonEmpty a Source #
Prepend a list to the front of a NonEmpty
.
>>>
prependList [] [1, 2, 3]
[1, 2, 3]
>>>
prependList [negate 1, 0] [1, 2, 3]
[-1, 0, 1, 2, 3]
Stream transformations
intersperse :: a -> NonEmpty a -> NonEmpty a Source #
Produces a NonEmpty
which alternates between elementes of
the input list, and the supplied element.
>>>
intersperse 0 [1, 2, 3])
[1, 0, 2, 0, 3]
>>>
intersperse 0 [1]
[1]
foldl1 :: (a -> a -> a) -> NonEmpty a -> a Source #
Left-associative fold, lazy in the accumulator. See foldl
.
foldl1' :: (a -> a -> a) -> NonEmpty a -> a Source #
Left-associative fold, strict in the accumulator. See foldl'
.
foldr1 :: (a -> a -> a) -> NonEmpty a -> a Source #
Left-associative fold, strict in the accumulator. See foldl'
.
scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b Source #
scanl is similar to foldl, but returns a stream of successive reduced values from the left:
>>>
scanl (+) 1 [20, 300, 4000]
[1,21,321,4321]
scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a Source #
scanl1 is a variant of scanl that has no starting value argument:
scanl1 f [x1, x2, ...] == [x1, x1f
x2, x1f
(x2f
x3), ...]
scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b Source #
Right-to-left dual of scanl. Note that the order of parameters on the accumulating function are reversed compared to scanl. Also note that
head (scanr f z xs) == foldr f z xs
>>>
scanr (+) 0 [1..4]
[10,9,7,4,0]
>>>
scanr (+) 42 []
[42]
>>>
scanr (-) 100 [1..4]
[98,-97,99,-96,100]
scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a Source #
scanr1 is a variant of scanr that has no starting value argument.
>>>
scanr1 (+) [1..4]
[10,9,7,4]
>>>
scanr1 (+) []
[]
>>>
scanr1 (-) [1..4]
[-2,3,-1,4]
transpose :: forall a. NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a) Source #
transpose for NonEmpty, behaves the same as transpose
.
The rows/columns need not be the same length, in which case
transpose . transpose /= id
sortOn :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a Source #
Sort a list on a projection of its elements.
Projects once, then sorts, then un-projects.
This is useful when the projection function is expensive.
If it's not, you should probably use sortWith
.
sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a Source #
Sort a list on a projection of its elements.
Projects during comparison.
This is useful when the projection function is cheap.
If it's not, you should probably use sortOn
.
Building streams
iterate :: (a -> a) -> a -> NonEmpty a Source #
iterate f x produces the infinite sequence of repeated applications of f to x.
iterate f x = [x, f x, f (f x), ..]
repeat :: a -> NonEmpty a Source #
repeat x returns a constant stream, where all elements are equal to x.
cycle :: NonEmpty a -> NonEmpty a Source #
cycle xs returns the infinite repetition of xs:
cycle [1, 2, 3] == [1, 2, 3, 1, 2, 3, ...]
insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a Source #
insert x xs inserts x into the last position in xs where it is still less than or equal to the next element. If the list is sorted beforehand, the result will also be sorted.
some1 :: Alternative f => f a -> f (NonEmpty a) Source #
some1 x sequences x one or more times.
Extracting sublists
drop :: Int -> NonEmpty a -> [a] Source #
drop n xs drops the first n elements from the front of the sequence xs.
takeWhile :: (a -> Bool) -> NonEmpty a -> [a] Source #
Produces the longest prefix of the stream for which the predicate holds.
dropWhile :: (a -> Bool) -> NonEmpty a -> [a] Source #
dropWhile p xs produces the suffix remaining after takeWhile p xs.
filter :: (a -> Bool) -> NonEmpty a -> [a] Source #
Removes any elements of a nonempty stream that do not satisfy a predicate.
group :: (Foldable f, Eq a) => f a -> [NonEmpty a] Source #
Takes a stream and returns a list of streams such that flattening the resulting list is equal to the argument. Moreover, each stream in the resulting list contains only equal elements.
>>>
group "Mississippi"
["M", "i", "ss", "i", "ss", "i", "pp", "i"]
groupAll :: Ord a => [a] -> [NonEmpty a] Source #
Similar to group
, but sorts the input first so that each
equivalence class has, at most, one list in the output.
groupAllBy :: (a -> a -> Ordering) -> [a] -> [NonEmpty a] Source #
Similar to groupBy
, but sorts the input first so that each
equivalence class has, at most, one list in the output.
groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a] Source #
Similar to group
, but uses the provided projection when comparing for equality.
groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a] Source #
Similar to groupWith
, but sorts the input first so that each
equivalence class has, at most, one list in the output.
group1 :: forall a. Eq a => NonEmpty a -> NonEmpty (NonEmpty a) Source #
Similar to group
, but uses the knowledge that its input is non-empty to
produce guaranteed non-empty output.
groupAll1 :: Ord a => NonEmpty a -> [NonEmpty a] Source #
Similar to group1
, but sorts the input first so that each
equivalence class has, at most, one list in the output.
groupAllBy1 :: (a -> a -> Ordering) -> [a] -> [NonEmpty a] Source #
Similar to group
, but sorts the input first so that each
equivalence class has, at most, one list in the output.
groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) Source #
Similar to group1
, but uses the provided projection when comparing for equality.
groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) Source #
Similar to groupWith1
, but sorts the list first so that each
equivalence class has, at most, one list in the output.
Sublist predicates
isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool Source #
Returns True if the first argument is a prefix of the second.
>>>
isPrefixOf [1, 2, 3] [1, 2, 3, 4, 5]
True>>>
isPrefixOf "abc" "defghi"
False>>>
isPrefixOf "abc" ""
False
Set operations
nub :: Eq a => NonEmpty a -> NonEmpty a Source #
Removes duplicate elements from a list. In particular, it keeps only
the first occurrence of each element. (The name nub means essence
.)
It is a special case of nubBy, which allows the programmer to supply
their own inequality test.
nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a Source #
Behaves just like nub, except it uses a user-supplied equality
predicate instead of the overloaded ==
function.
Indexing streams
(!?) :: NonEmpty a -> Int -> Maybe a infixl 9 Source #
xs !! n returns the element of the stream xs at index n, if present. Note that the head of the stream has index 0.