rosso-1.0: General purpose utility library

Data.List.Rosso1

Description

Extends Data.List

Synopsis

Documentation

module Data.List

dropEachElem :: [a] -> [[a]]Source

Returns a list of lists, each obtained by dropping a single element of the argument.

>>> dropEachElem "abcd"
["bcd","acd","abd","abc"]

extractEachElem :: [a] -> [(a, [a])]Source

Similar to dropEachElem, but each output list is paired with the element that was dropped.

>>> extractEachElem "abcd"
[('a',"bcd"),('b',"acd"),('c',"abd"),('d',"abc")]

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

Sorts, then groups the elements of a list, using a specified key function. The sorting process is stable, i.e. elements with equal keys remain in the same order.

>>> sortAndGroupOn (`mod` 3) [1..10]
[[3,6,9],[1,4,7,10],[2,5,8]]

alistCollect :: Ord k => [(k, a)] -> [(k, [a])]Source

Collects together the list of values corresponding to each unique key in an association list. Entries in the output list are arranged in ascending order of key. The ordering of values corresponding to a given key is preserved from input to output.

>>> alistCollect [(7, 'a'), (3, 'a'), (5, 'x'), (3, 'a'), (3, 'b')]
[(3,"aab"),(5,"x"),(7,"a")]

zipFilter :: [Bool] -> [a] -> [a]Source

Filters a list of values according to a list of corresponding boolean flags.

>>> zipFilter [False, True, False, True, True] [0..]
[1,3,4]