Portability | H98 |
---|---|

Stability | experimental |

Maintainer | Douglas Burke |

This module defines some generic list and related helper functions.

- select :: (a -> Bool) -> [a] -> [b] -> [b]
- deleteIndex :: [a] -> Int -> [a]
- subset :: Eq a => [a] -> [a] -> Bool
- equiv :: Eq a => [a] -> [a] -> Bool
- addSetElem :: Eq a => a -> [a] -> [a]
- headOrNothing :: [Maybe a] -> Maybe a
- pairUngroup :: (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]]
- permutations :: [a] -> [[a]]
- listProduct :: [[a]] -> [[a]]
- powerSequencesLen :: Int -> [a] -> [[a]]
- flist :: [a -> b] -> a -> [b]
- 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.

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.

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

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.

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`

powerSequencesLen :: Int -> [a] -> [[a]]Source

Return all powersequences of a given length