swish-0.3.0.1: A semantic web toolkit.

PortabilityH98
Stabilityexperimental
MaintainerDouglas Burke

Swish.Utils.ListHelpers

Description

This module defines some generic list and related helper functions.

Synopsis

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.

subset :: Eq a => [a] -> [a] -> BoolSource

Subset test

equiv :: Eq a => [a] -> [a] -> BoolSource

Set equivalence test

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

pairSort :: Ord a => [(a, b)] -> [(a, b)]Source

pairGroup :: Ord a => [(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

anyf :: (b -> Bool) -> [a -> b] -> a -> BoolSource

Test if application of any functions in list to a given value satisfies a given condition

allp :: [a -> Bool] -> a -> BoolSource

Test if a value satisfies all predicates in a list

anyp :: [a -> Bool] -> a -> BoolSource

Test if a value satisfies any predicate in a list