Safe Haskell | None |
---|---|
Language | Haskell98 |
Utitlity functions on lists.
- caseList :: [a] -> b -> (a -> [a] -> b) -> b
- listCase :: b -> (a -> [a] -> b) -> [a] -> b
- headMaybe :: [a] -> Maybe a
- headWithDefault :: a -> [a] -> a
- lastMaybe :: [a] -> Maybe a
- uncons :: [a] -> Maybe (a, [a])
- mcons :: Maybe a -> [a] -> [a]
- initLast :: [a] -> Maybe ([a], a)
- (!!!) :: [a] -> Int -> Maybe a
- downFrom :: Integral a => a -> [a]
- updateHead :: (a -> a) -> [a] -> [a]
- spec_updateHead :: (a -> a) -> [a] -> [a]
- prop_updateHead :: Eq a => (a -> a) -> [a] -> Bool
- updateLast :: (a -> a) -> [a] -> [a]
- spec_updateLast :: (a -> a) -> [a] -> [a]
- prop_updateLast :: Eq a => (a -> a) -> [a] -> Bool
- updateAt :: Int -> (a -> a) -> [a] -> [a]
- spec_updateAt :: Int -> (a -> a) -> [a] -> [a]
- prop_updateAt :: Eq a => NonNegative Int -> (a -> a) -> [a] -> Bool
- mapEither :: (a -> Either b c) -> [a] -> ([b], [c])
- deal :: (a -> Either b c) -> a -> ([b], [c]) -> ([b], [c])
- takeWhileJust :: (a -> Maybe b) -> [a] -> [b]
- spanJust :: (a -> Maybe b) -> [a] -> ([b], [a])
- partitionMaybe :: (a -> Maybe b) -> [a] -> ([a], [b])
- isSublistOf :: Eq a => [a] -> [a] -> Bool
- type Prefix a = [a]
- type Suffix a = [a]
- maybePrefixMatch :: Eq a => Prefix a -> [a] -> Maybe (Suffix a)
- data PreOrSuffix a
- preOrSuffix :: Eq a => [a] -> [a] -> PreOrSuffix a
- wordsBy :: (a -> Bool) -> [a] -> [[a]]
- chop :: Int -> [a] -> [[a]]
- holes :: [a] -> [(a, [a])]
- sorted :: Ord a => [a] -> Bool
- distinct :: Eq a => [a] -> Bool
- fastDistinct :: Ord a => [a] -> Bool
- prop_distinct_fastDistinct :: [Integer] -> Bool
- allEqual :: Eq a => [a] -> Bool
- duplicates :: Ord a => [a] -> [a]
- groupBy' :: (a -> a -> Bool) -> [a] -> [[a]]
- prop_groupBy' :: (Bool -> Bool -> Bool) -> [Bool] -> Property
- groupOn :: Ord b => (a -> b) -> [a] -> [[a]]
- splitExactlyAt :: Integral n => n -> [a] -> Maybe ([a], [a])
- extractNthElement' :: Integral i => i -> [a] -> ([a], a, [a])
- extractNthElement :: Integral i => i -> [a] -> (a, [a])
- prop_extractNthElement :: Integer -> [Integer] -> Property
- genericElemIndex :: (Eq a, Integral i) => a -> [a] -> Maybe i
- prop_genericElemIndex :: Integer -> [Integer] -> Property
- zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
- prop_zipWith' :: (Integer -> Integer -> Integer) -> Property
- uniqOn :: Ord b => (a -> b) -> [a] -> [a]
- prop_uniqOn :: [Integer] -> Bool
- commonSuffix :: Eq a => [a] -> [a] -> [a]
- commonPrefix :: Eq a => [a] -> [a] -> [a]
- prop_commonPrefix :: [Integer] -> [Integer] -> [Integer] -> Bool
- prop_commonSuffix :: [Integer] -> [Integer] -> [Integer] -> Bool
- tests :: IO Bool
Documentation
caseList :: [a] -> b -> (a -> [a] -> b) -> b Source
Case distinction for lists, with list first.
Cf. ifNull
.
headWithDefault :: a -> [a] -> a Source
Head function (safe). Returns a value on empty lists.
headWithDefault 42 [] = 42 headWithDefault 42 [1,2,3] = 1
updateHead :: (a -> a) -> [a] -> [a] Source
Update the first element of a list, if it exists.
spec_updateHead :: (a -> a) -> [a] -> [a] Source
prop_updateHead :: Eq a => (a -> a) -> [a] -> Bool Source
updateLast :: (a -> a) -> [a] -> [a] Source
Update the last element of a list, if it exists.
spec_updateLast :: (a -> a) -> [a] -> [a] Source
prop_updateLast :: Eq a => (a -> a) -> [a] -> Bool Source
updateAt :: Int -> (a -> a) -> [a] -> [a] Source
Update nth element of a list, if it exists. Precondition: the index is >= 0.
spec_updateAt :: Int -> (a -> a) -> [a] -> [a] Source
prop_updateAt :: Eq a => NonNegative Int -> (a -> a) -> [a] -> Bool Source
mapEither :: (a -> Either b c) -> [a] -> ([b], [c]) Source
A generalized version of partition
.
(Cf. mapMaybe
vs. filter
).
takeWhileJust :: (a -> Maybe b) -> [a] -> [b] Source
A generalized version of takeWhile
.
(Cf. mapMaybe
vs. filter
).
partitionMaybe :: (a -> Maybe b) -> [a] -> ([a], [b]) Source
isSublistOf :: Eq a => [a] -> [a] -> Bool Source
Sublist relation.
maybePrefixMatch :: Eq a => Prefix a -> [a] -> Maybe (Suffix a) Source
Check if a list has a given prefix. If so, return the list minus the prefix.
data PreOrSuffix a Source
Result of preOrSuffix
.
preOrSuffix :: Eq a => [a] -> [a] -> PreOrSuffix a Source
Compare lists with respect to prefix partial order.
wordsBy :: (a -> Bool) -> [a] -> [[a]] Source
Split a list into sublists. Generalisation of the prelude function
words
.
words xs == wordsBy isSpace xs
sorted :: Ord a => [a] -> Bool Source
Check whether a list is sorted.
Assumes that the Ord
instance implements a partial order.
distinct :: Eq a => [a] -> Bool Source
Check whether all elements in a list are distinct from each
other. Assumes that the Eq
instance stands for an equivalence
relation.
fastDistinct :: Ord a => [a] -> Bool Source
prop_distinct_fastDistinct :: [Integer] -> Bool Source
allEqual :: Eq a => [a] -> Bool Source
Checks if all the elements in the list are equal. Assumes that
the Eq
instance stands for an equivalence relation.
duplicates :: Ord a => [a] -> [a] Source
Returns an (arbitrary) representative for each list element that occurs more than once.
groupBy' :: (a -> a -> Bool) -> [a] -> [[a]] Source
A variant of groupBy
which applies the predicate to consecutive
pairs.
splitExactlyAt :: Integral n => n -> [a] -> Maybe ([a], [a]) Source
splitExactlyAt n xs = Just (ys, zs)
iff xs = ys ++ zs
and genericLength ys = n
.
extractNthElement' :: Integral i => i -> [a] -> ([a], a, [a]) Source
gives the extractNthElement
n xsn
-th element in xs
(counting from 0), plus the remaining elements (preserving order).
extractNthElement :: Integral i => i -> [a] -> (a, [a]) Source
prop_extractNthElement :: Integer -> [Integer] -> Property Source
genericElemIndex :: (Eq a, Integral i) => a -> [a] -> Maybe i Source
A generalised variant of elemIndex
.
prop_genericElemIndex :: Integer -> [Integer] -> Property Source
prop_zipWith' :: (Integer -> Integer -> Integer) -> Property Source
uniqOn :: Ord b => (a -> b) -> [a] -> [a] Source
Efficient version of nub that sorts the list via a search tree (Map
).
prop_uniqOn :: [Integer] -> Bool Source
commonSuffix :: Eq a => [a] -> [a] -> [a] Source
Compute the common suffix of two lists.
commonPrefix :: Eq a => [a] -> [a] -> [a] Source
Compute the common prefix of two lists.