- inits :: [a] -> [[a]]
- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
- group :: Eq a => [a] -> [[a]]
- partition :: (a -> Bool) -> [a] -> ([a], [a])
- chop :: (a -> Bool) -> [a] -> [[a]]
- breakAfter :: (a -> Bool) -> [a] -> ([a], [a])
- segmentAfter :: (a -> Bool) -> [a] -> [[a]]
- segmentBefore :: (a -> Bool) -> [a] -> [[a]]
- splitLast :: [a] -> ([a], a)
- viewL :: [a] -> Maybe (a, [a])
- viewR :: [a] -> Maybe ([a], a)
- switchL :: b -> (a -> [a] -> b) -> [a] -> b
- switchR :: b -> ([a] -> a -> b) -> [a] -> b
- dropWhileRev :: (a -> Bool) -> [a] -> [a]
- takeWhileRev :: (a -> Bool) -> [a] -> [a]
- maybePrefixOf :: Eq a => [a] -> [a] -> Maybe [a]
- partitionMaybe :: (a -> Maybe b) -> [a] -> ([b], [a])
- unzipEithers :: [Either a b] -> ([a], [b])
- sieve :: Int -> [a] -> [a]
- sliceHorizontal :: Int -> [a] -> [[a]]
- sliceVertical :: Int -> [a] -> [[a]]
- search :: Eq a => [a] -> [a] -> [Int]
- replace :: Eq a => [a] -> [a] -> [a] -> [a]
- multiReplace :: Eq a => [([a], [a])] -> [a] -> [a]
- shear :: [[a]] -> [[a]]
- shearTranspose :: [[a]] -> [[a]]
- outerProduct :: (a -> b -> c) -> [a] -> [b] -> [[c]]
- takeWhileMulti :: [a -> Bool] -> [a] -> [a]
- rotate :: Int -> [a] -> [a]
- mergeBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- allEqual :: Eq a => [a] -> Bool
- isAscending :: Ord a => [a] -> Bool
- isAscendingLazy :: Ord a => [a] -> [Bool]
- mapAdjacent :: (a -> a -> b) -> [a] -> [b]
- range :: Num a => Int -> [a]
- padLeft :: a -> Int -> [a] -> [a]
- padRight :: a -> Int -> [a] -> [a]
- iterateAssociative :: (a -> a -> a) -> a -> [a]
- iterateLeaky :: (a -> a -> a) -> a -> [a]
Improved standard functions
This function is lazier than the one suggested in the Haskell 98 report.
inits undefined =  : undefined,
in contrast to
Data.List.inits undefined = undefined.
This function compares adjacent elements of a list. If two adjacent elements satisfy a relation then they are put into the same sublist. Example:
groupBy (<) "abcdebcdef" == ["abcde","bcdef"]
In contrast to that
the head of each sublist with each candidate for this sublist.
List.groupBy (<) "abcdebcdef" == ["abcdebcdef"]
is compared with the leading
Thus it is put into the same sublist as
The sublists are never empty.
Thus the more precise result type would be
Data.List.partition of GHC 6.2.1 fails on infinite lists.
But this one does not.
Split the list at the occurrences of a separator into sub-lists.
Remove the separators.
This is a generalization of
break, but splits after the matching element.
Split the list after each occurence of a terminator. Keep the terminator. There is always a list for the part after the last terminator. It may be empty.
Split the list before each occurence of a leading character. Keep these characters. There is always a list for the part before the first leading character. It may be empty.
splitLast xs == (init xs, last xs),
splitLast is more efficient
if the last element is accessed after the initial ones,
because it avoids memoizing list.
List processing starting at the end
Remove the longest suffix of elements satisfying p.
In contrast to
reverse . dropWhile p . reverse
this works for infinite lists, too.
Alternative version of
reverse . takeWhile p . reverse.
List processing with Maybe and Either
maybePrefixOf xs ys is
Just zs if
xs is a prefix of
ys without the prefix
Otherwise it is
Partition a list into elements which evaluate to
Sieve and slice
Lists of lists
[[00,01,02,...], [, [10,11,12,...], --> [10,01], [20,21,22,...], [20,11,02], ...] ...]
concat . shear you can perform a Cantor diagonalization,
that is an enumeration of all elements of the sub-lists
where each element is reachable within a finite number of steps.
It is also useful for polynomial multiplication (convolution).
Operate on each combination of elements of the first and the second list.
In contrast to the list instance of
in holds the results in a list of lists.
concat (outerProduct f xs ys) == liftM2 f xs ys
Take while first predicate holds, then continue taking while second predicate holds, and so on.
Given two lists that are ordered
p x y holds for subsequent
mergeBy them into a list that is ordered, again.
For an associative operation
op this computes
iterateAssociative op a = iterate (op a) a
but it is even faster than
map (powerAssociative op a a) [0..]
since it shares temporary results.
The idea is:
From the list
map (powerAssociative op a a) [0,(2*n)..]
we compute the list
map (powerAssociative op a a) [0,n..],
and iterate that until
This is equal to
The idea is the following:
The list we search is the fixpoint of the function:
Square all elements of the list,
then spread it and fill the holes with successive numbers
of their left neighbour.
This also preserves log n applications per value.
However it has a space leak,
because for the value with index
all elements starting at
div n 2 must be kept.