class (IsList full, item ~ Item full, FoldableLL full item, Monoid full) => ListLike full item | full -> item whereThe class implementing list-like functions.
It is worth noting that types such as Data.Map.Map can be instances of
ListLike. Due to their specific ways of operating, they may not behave
in the expected way in some cases. For instance, cons may not increase
the size of a map if the key you have given is already in the map; it will
just replace the value already there.
Implementators must define at least:
singleton
head
tail
null or genericLength
Methods
empty :: fullThe empty list
singleton :: item -> fullCreates a single-element list out of an element
cons :: item -> full -> fullLike (:) for lists: adds an element to the beginning of a list
snoc :: full -> item -> fullAdds an element to the *end* of a ListLike.
append :: full -> full -> fullCombines two lists. Like (++).
head :: full -> itemExtracts the first element of a ListLike.
uncons :: full -> Maybe (item, full)Extract head and tail, return Nothing if empty
last :: full -> itemExtracts the last element of a ListLike.
tail :: full -> fullGives all elements after the head.
init :: full -> fullAll elements of the list except the last one. See also inits.
null :: full -> BoolTests whether the list is empty.
length :: full -> IntLength of the list. See also genericLength.
map :: ListLike full' item' => (item -> item') -> full -> full'rigidMap :: (item -> item) -> full -> fullLike map, but without the possibility of changing the type of the item. This can have performance benefits for things such as ByteStrings, since it will let the ByteString use its native low-level map implementation.
reverse :: full -> fullReverse the elements in a list.
intersperse :: item -> full -> fullAdd an item between each element in the structure
concat :: ListLike full' full => full' -> fullFlatten the structure.
concatMap :: ListLike full' item' => (item -> full') -> full -> full'Map a function over the items and concatenate the results. See also rigidConcatMap.
rigidConcatMap :: (item -> full) -> full -> fullLike concatMap, but without the possibility of changing the type of the item. This can have performance benefits for some things such as ByteString.
any :: (item -> Bool) -> full -> BoolTrue if any items satisfy the function
all :: (item -> Bool) -> full -> BoolTrue if all items satisfy the function
maximum :: Ord item => full -> itemThe maximum value of the list
minimum :: Ord item => full -> itemThe minimum value of the list
replicate :: Int -> item -> fullGenerate a structure with the specified length with every element set to the item passed in. See also genericReplicate
take :: Int -> full -> fullTakes the first n elements of the list. See also genericTake.
drop :: Int -> full -> fullDrops the first n elements of the list. See also genericDrop
splitAt :: Int -> full -> (full, full)Equivalent to
(take n xs, drop n xs). See also genericSplitAt.takeWhile :: (item -> Bool) -> full -> fullReturns all elements at start of list that satisfy the function.
dropWhile :: (item -> Bool) -> full -> fullDrops all elements from the start of the list that satisfy the function.
dropWhileEnd :: (item -> Bool) -> full -> fullDrops all elements from the end of the list that satisfy the function.
span :: (item -> Bool) -> full -> (full, full)break :: (item -> Bool) -> full -> (full, full)group :: (ListLike full' full, Eq item) => full -> full'Split a list into sublists, each which contains equal arguments. For order-preserving types, concatenating these sublists will produce the original list. See also groupBy.
inits :: ListLike full' full => full -> full'All initial segments of the list, shortest first
tails :: ListLike full' full => full -> full'All final segnemts, longest first
isPrefixOf :: Eq item => full -> full -> BoolTrue when the first list is at the beginning of the second.
isSuffixOf :: Eq item => full -> full -> BoolTrue when the first list is at the beginning of the second.
isInfixOf :: Eq item => full -> full -> BoolTrue when the first list is wholly containted within the second
stripPrefix :: Eq item => full -> full -> Maybe fullRemove a prefix from a listlike if possible
stripSuffix :: Eq item => full -> full -> Maybe fullRemove a suffix from a listlike if possible
elem :: Eq item => item -> full -> BoolTrue if the item occurs in the list
notElem :: Eq item => item -> full -> BoolTrue if the item does not occur in the list
find :: (item -> Bool) -> full -> Maybe itemTake a function and return the first matching element, or Nothing if there is no such element.
filter :: (item -> Bool) -> full -> fullReturns only the elements that satisfy the function.
partition :: (item -> Bool) -> full -> (full, full)index :: full -> Int -> itemThe element at 0-based index i. Raises an exception if i is out of bounds. Like (!!) for lists.
elemIndex :: Eq item => item -> full -> Maybe IntReturns the index of the element, if it exists.
elemIndices :: (Eq item, ListLike result Int) => item -> full -> resultReturns the indices of the matching elements. See also findIndices
findIndex :: (item -> Bool) -> full -> Maybe IntTake a function and return the index of the first matching element, or Nothing if no element matches
findIndices :: ListLike result Int => (item -> Bool) -> full -> resultReturns the indices of all elements satisfying the function
sequence :: (Applicative m, ListLike fullinp (m item)) => fullinp -> m fullEvaluate each action in the sequence and collect the results
mapM :: (Applicative m, ListLike full' item') => (item -> m item') -> full -> m full'rigidMapM :: Monad m => (item -> m item) -> full -> m fullLike mapM, but without the possibility of changing the type of the item. This can have performance benefits with some types.
nub :: Eq item => full -> fullRemoves duplicate elements from the list. See also nubBy
delete :: Eq item => item -> full -> fullRemoves the first instance of the element from the list. See also deleteBy
deleteFirsts :: Eq item => full -> full -> fullList difference. Removes from the first list the first instance of each element of the second list. See
(\\)and deleteFirstsByunion :: Eq item => full -> full -> fullList union: the set of elements that occur in either list. Duplicate elements in the first list will remain duplicate. See also unionBy.
intersect :: Eq item => full -> full -> fullList intersection: the set of elements that occur in both lists. See also intersectBy
sort :: Ord item => full -> fullSorts the list. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. See also sortBy.
insert :: Ord item => item -> full -> fullInserts the element at the last place where it is still less than or equal to the next element. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. On types such as maps, this may result in changing an existing item. See also insertBy.
toList' :: full -> [item]Converts the structure to a list. This is logically equivolent to fromListLike, but may have a more optimized implementation. These two functions are now retired in favor of the methods of IsList, but they are retained here because some instances still use this implementation.
fromList' :: [item] -> fullGenerates the structure from a list.
fromListLike :: ListLike full' item => full -> full'Converts one ListLike to another. See also toList'. Default implementation is
fromListLike = map idnubBy :: (item -> item -> Bool) -> full -> fullGeneric version of nub
deleteBy :: (item -> item -> Bool) -> item -> full -> fullGeneric version of deleteBy
deleteFirstsBy :: (item -> item -> Bool) -> full -> full -> fullGeneric version of deleteFirsts
unionBy :: (item -> item -> Bool) -> full -> full -> fullGeneric version of union
intersectBy :: (item -> item -> Bool) -> full -> full -> fullGeneric version of intersect
groupBy :: (ListLike full' full, Eq item) => (item -> item -> Bool) -> full -> full'Generic version of group.
sortBy :: (item -> item -> Ordering) -> full -> fullSort function taking a custom comparison function
insertBy :: (item -> item -> Ordering) -> item -> full -> fullLike insert, but with a custom comparison function
genericLength :: Num a => full -> aLength of the list
genericTake :: Integral a => a -> full -> fullGeneric version of take
genericDrop :: Integral a => a -> full -> fullGeneric version of drop
genericSplitAt :: Integral a => a -> full -> (full, full)Generic version of splitAt
genericReplicate :: Integral a => a -> item -> fullGeneric version of replicate
Instances19ListLike, …
ListLike CharString CharDefined in ListLike-4.7.8.4 · Data.ListLike.CharStringListLike CharStringLazy CharDefined in ListLike-4.7.8.4 · Data.ListLike.CharStringListLike Chars CharDefined in ListLike-4.7.8.4 · Data.ListLike.CharsListLike ByteString Word8Defined in ListLike-4.7.8.4 · Data.ListLike.Instances · orphanListLike ByteString Word8Defined in ListLike-4.7.8.4 · Data.ListLike.Instances · orphanListLike Text CharDefined in ListLike-4.7.8.4 · Data.ListLike.Text.Text · orphanListLike Builder CharDefined in ListLike-4.7.8.4 · Data.ListLike.Text.Builder · orphanListLike Text CharDefined in ListLike-4.7.8.4 · Data.ListLike.Text.TextLazy · orphanListLike (Seq a) aDefined in ListLike-4.7.8.4 · Data.ListLike.Instances · orphanListLike (DList a) aDefined in ListLike-4.7.8.4 · Data.ListLike.DList · orphanListLike (FMList a) aDefined in ListLike-4.7.8.4 · Data.ListLike.FMList · orphanListLike (UTF8 ByteString) CharDefined in ListLike-4.7.8.4 · Data.ListLike.UTF8 · orphanListLike (UTF8 ByteString) CharDefined in ListLike-4.7.8.4 · Data.ListLike.UTF8 · orphanListLike (Vector a) aDefined in ListLike-4.7.8.4 · Data.ListLike.Vector.Vector · orphanListLike [a] aDefined in ListLike-4.7.8.4 · Data.ListLike.BaseStorable a => ListLike (Vector a) aDefined in ListLike-4.7.8.4 · Data.ListLike.Vector.Storable · orphanUnbox a => ListLike (Vector a) aDefined in ListLike-4.7.8.4 · Data.ListLike.Vector.Unboxed · orphan(IsList (v a), Item (v a) ~ a, Monoid (v a), Eq (v a), Vector v a) => ListLike (v a) aDefined in ListLike-4.7.8.4 · Data.ListLike.Vector.Generic · orphan(Integral i, Ix i) => ListLike (Array i e) eDefined in ListLike-4.7.8.4 · Data.ListLike.Instances · orphan