Portability | H98 |
---|---|
Stability | experimental |
Maintainer | Douglas Burke |
This module defines some generic list and related helper functions.
- select :: (a -> Bool) -> [a] -> [b] -> [b]
- mapset :: Eq b => (a -> b) -> [a] -> [b]
- deleteIndex :: [a] -> Int -> [a]
- subset :: Eq a => [a] -> [a] -> Bool
- equiv :: Eq a => [a] -> [a] -> Bool
- hasPartitions :: Eq a => [a] -> ([a], [a]) -> Bool
- addSetElem :: Eq a => a -> [a] -> [a]
- headOrNothing :: [Maybe a] -> Maybe a
- pairUngroup :: (a, [b]) -> [(a, b)]
- pairsUngroup :: [(a, [b])] -> [(a, b)]
- pairSort :: Ord a => [(a, b)] -> [(a, b)]
- pairGroup :: Ord a => [(a, b)] -> [(a, [b])]
- breakAll :: (a -> Bool) -> [a] -> [[a]]
- powerSet :: [a] -> [[a]]
- combinations :: Int -> [a] -> [[a]]
- permutations :: [a] -> [[a]]
- listProduct :: [[a]] -> [[a]]
- powerSequences :: [a] -> [[a]]
- powerSequences_len :: Int -> [a] -> [[a]]
- powerSequences_inf :: [a] -> [[a]]
- flist :: [a -> b] -> a -> [b]
- ffold :: (b -> c -> c) -> c -> [a -> b] -> a -> c
- allf :: (b -> Bool) -> [a -> b] -> a -> Bool
- anyf :: (b -> Bool) -> [a -> b] -> a -> Bool
- allp :: [a -> Bool] -> a -> Bool
- anyp :: [a -> Bool] -> a -> Bool
Documentation
select :: (a -> Bool) -> [a] -> [b] -> [b]Source
Select is like filter, except that it tests one list to select elements from a second list.
mapset :: Eq b => (a -> b) -> [a] -> [b]Source
Collect set of values from list under supplied mapping function
deleteIndex :: [a] -> Int -> [a]Source
Delete the n'th element of a list, returning the result
If the list doesn't have an n'th element, return the list unchanged.
hasPartitions :: Eq a => [a] -> ([a], [a]) -> BoolSource
Set partition test
Is it possible to be more efficient here? Maybe something like sort/merge/compare?
addSetElem :: Eq a => a -> [a] -> [a]Source
Add element to set
headOrNothing :: [Maybe a] -> Maybe aSource
Return head of a list of Maybe
's, or Nothing
if list is empty
Use with filter isJust
to select a non-Nothing value from a
list when such a value is present.
pairUngroup :: (a, [b]) -> [(a, b)]Source
pairsUngroup :: [(a, [b])] -> [(a, b)]Source
breakAll :: (a -> Bool) -> [a] -> [[a]]Source
Break list into a list of sublists, separated by element satisfying supplied condition.
powerSet :: [a] -> [[a]]Source
Powerset of a list, in ascending order of size. Assumes the supplied list has no duplicate elements.
combinations :: Int -> [a] -> [[a]]Source
Combinations of n elements from a list, each being returned in the order that they appear in the list.
permutations :: [a] -> [[a]]Source
listProduct :: [[a]] -> [[a]]Source
Given a list of lists, construct a new list of lists where each member of the new list is the same length as the original list, and each member corresponds to a different choice of one element from each of the original members in the corresponding position. Thus:
listProduct [[a1,a2],[b1],[c1,c2]] = [ [a1,b1,c1], [a1,b1,c2], [a2,b1,c1], [a2,b1,c2] ]
Note: The length of the resulting list is the prodicty of lengths of the components of the original list. Thus, if any member of the original list is empty then so is the resulting list:
listProduct [[a1,a2],[],[c1,c2]] = []
NOTE: this is subsumed by sequence
powerSequences :: [a] -> [[a]]Source
Function to choose all sequences of any length from a supplied set of values, returned in increasing length.
powerSequences_len :: Int -> [a] -> [[a]]Source
Return all powersequences of a given length
powerSequences_inf :: [a] -> [[a]]Source
Return all powersequences of indefinite length Observe that any such powersequence will consist of a sequence of a finite length sequence followed by an indefinite number of copies of the head of the base set. To prevent duplicates, the generator constructs only sequences that do not end in the first member of the base set.
flist :: [a -> b] -> a -> [b]Source
Apply list of functions to some value, returning list of results. It's kind of like an converse map.
This is similar to the ap
function in the Monad library.
ffold :: (b -> c -> c) -> c -> [a -> b] -> a -> cSource
Fold result from list of functions applied to some value, returning the result of the fold.
This is similar to the ap
function in the Monad library.
allf :: (b -> Bool) -> [a -> b] -> a -> BoolSource
Test if application of all functions in list to a given value satisfies a given condition