| Copyright | (C) 2011-2015 Edward Kmett (C) 2010 Tony Morris Oliver Taylor Eelis van der Weegen |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Data.List.NonEmpty
Contents
Description
ANonEmpty list is one which always has at least one element, but is otherwise identical to the traditional list type in complexity and in terms of API. You will almost certainly want to import this modulequalified.
Since: 4.9.0.0
Non-empty (and non-strict) list type.
Since: 4.9.0.0
Constructors
| a:| [a]infixr 5 |
intersperse :: a ->NonEmpty a ->NonEmpty aSource#
'intersperse x xs' alternates elements of the list with copies ofx.
intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3]
uncons ::NonEmpty a -> (a,Maybe (NonEmpty a))Source#
uncons produces the first element of the stream, and a stream of the remaining elements, if any.
inits ::Foldable f => f a ->NonEmpty [a]Source#
Theinits function takes a streamxs and returns all the finite prefixes ofxs.
tails ::Foldable f => f a ->NonEmpty [a]Source#
Thetails function takes a streamxs and returns all the suffixes ofxs.
iterate :: (a -> a) -> a ->NonEmpty aSource#
produces the infinite sequence of repeated applications ofiterate f xf tox.
iterate f x = x :| [f x, f (f x), ..]
repeat :: a ->NonEmpty aSource#
returns a constant stream, where all elements are equal torepeat xx.
cycle ::NonEmpty a ->NonEmpty aSource#
returns the infinite repetition ofcycle xsxs:
cycle (1 :| [2,3]) = 1 :| [2,3,1,2,3,...]
insert :: (Foldable f,Ord a) => a -> f a ->NonEmpty aSource#
insertsinsert x xsx into the last position inxs where it is still less than or equal to the next element. In particular, if the list is sorted beforehand, the result will also be sorted.
drop ::Int ->NonEmpty a -> [a]Source#
drops the firstdrop n xsn elements off the front of the sequencexs.
splitAt ::Int ->NonEmpty a -> ([a], [a])Source#
returns a pair consisting of the prefix ofsplitAt n xsxs of lengthn and the remaining stream immediately following this prefix.
'splitAt' n xs == ('take' n xs, 'drop' n xs)xs == ys ++ zs where (ys, zs) = 'splitAt' n xstakeWhile :: (a ->Bool) ->NonEmpty a -> [a]Source#
returns the longest prefix of the streamtakeWhile p xsxs for which the predicatep holds.
span :: (a ->Bool) ->NonEmpty a -> ([a], [a])Source#
returns the longest prefix ofspan p xsxs that satisfiesp, together with the remainder of the stream.
'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)xs == ys ++ zs where (ys, zs) = 'span' p xsfilter :: (a ->Bool) ->NonEmpty a -> [a]Source#
removes any elements fromfilter p xsxs that do not satisfyp.
partition :: (a ->Bool) ->NonEmpty a -> ([a], [a])Source#
Thepartition function takes a predicatep and a streamxs, and returns a pair of lists. The first list corresponds to the elements ofxs for whichp holds; the second corresponds to the elements ofxs for whichp does not hold.
'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)group :: (Foldable f,Eq a) => f a -> [NonEmpty a]Source#
Thegroup function 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. For example, in list notation:
'group' $ 'cycle' "Mississippi" = "M" : "i" : "ss" : "i" : "ss" : "i" : "pp" : "i" : "M" : "i" : ...
groupAllWith ::Ord b => (a -> b) -> [a] -> [NonEmpty a]Source#
groupAllWith operates likegroupWith, but sorts the list 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#
groupWith1 is togroup1 asgroupWith is togroup
groupAllWith1 ::Ord b => (a -> b) ->NonEmpty a ->NonEmpty (NonEmpty a)Source#
groupAllWith1 is togroupWith1 asgroupAllWith is togroupWith
isPrefixOf ::Eq a => [a] ->NonEmpty a ->BoolSource#
TheisPrefix function returnsTrue if the first argument is a prefix of the second.
(!!) ::NonEmpty a ->Int -> ainfixl 9Source#
xs !! n returns the element of the streamxs at indexn. Note that the head of the stream has index 0.
Beware: a negative or out-of-bounds index will cause an error.
zip ::NonEmpty a ->NonEmpty b ->NonEmpty (a, b)Source#
Thezip function takes two streams and returns a stream of corresponding pairs.
fromList :: [a] ->NonEmpty aSource#
Converts a normal list to aNonEmpty stream.
Raises an error if given an empty list.
Produced byHaddock version 2.20.0