swish-0.6.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.

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

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

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.

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

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.

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