raft-0.3.7.0: Miscellaneous Haskell utilities for data structures and data manipulation.

Safe HaskellSafe
LanguageHaskell2010

Data.List.Util

Contents

Description

Miscellaneous functions for manipulating lists.

Synopsis

Subsets

hasSubset Source #

Arguments

:: Eq a 
=> [a]

The potential superset.

-> [a]

The potential subset

-> Bool

Whether the first set has the second as a subset.

Test for containment.

disjoint Source #

Arguments

:: Eq a 
=> [a]

The first set.

-> [a]

The second set.

-> Bool

Whether the sets are disjoint.

Test for disjointness.

replaceByFst Source #

Arguments

:: Eq a 
=> (a, b)

The replacement key and value.

-> [(a, b)]

The lookup table.

-> [(a, b)]

The updated table.

Replace the first occurrence in a lookup table.

noDuplicates Source #

Arguments

:: Eq a 
=> [a]

The list.

-> Bool

Whether the list does not contain duplicates.

Test for duplicates.

sameElements Source #

Arguments

:: Ord a 
=> [a]

The first list.

-> [a]

The second list.

-> Bool

Whether the lists have the same elements.

Test for same elements.

notDuplicatedIn Source #

Arguments

:: Eq b 
=> (a -> b)

The equality test.

-> a

The value.

-> [a]

The list.

-> Bool

Whether the value is in the list.

Test for membership of an element in a list.

deleteOn :: Eq b => (a -> b) -> a -> [a] -> [a] Source #

Delete using a function to extract values.

maybeList :: [a] -> Maybe [a] Source #

Lift a non-empty list.

Permutations

elemPermutation :: Eq a => [a] -> [a] -> Maybe [Int] Source #

Find the permutation of one list relative to another.

Grouping and sorting

groupOn :: Eq b => (a -> b) -> [a] -> [[a]] Source #

Group using a function to extract values.

nubOn :: Eq b => (a -> b) -> [a] -> [a] Source #

Nub using a function to extract values.

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

Sort using a function to extract values.

sortedGroups :: Ord b => [(b, c)] -> [(b, [c])] Source #

Sort and group.

sortedGroupsOn :: Ord b => (a -> b) -> (a -> c) -> [a] -> [(b, [c])] Source #

Sort and group using a function to extract values.

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

Sort and regroup elements of an association using its keys.

regroupBy Source #

Arguments

:: Ord a 
=> ([b] -> c)

The function for summarizing the second element of pairs.

-> [(a, b)]

The associations.

-> [(a, c)]

The regrouped associations.

Sort and regroup elements of an association using its keys.

Bounded enumerations.

domain :: (Bounded a, Enum a) => [a] Source #

Ordered list of values in a bounded enumeration.

Permutations.

powerSet :: [a] -> [[a]] Source #

Generate a power set. The algorithm used here is from http://evan-tech.livejournal.com/220036.html.

powerSetPermutations :: [a] -> [[a]] Source #

Generate a power set's permutations.

uniquePowerSetPermutations :: Eq a => [a] -> [[a]] Source #

Generate a power set's unique permutations.

suffixes :: [a] -> [[a]] Source #

A list of suffixes of another list.

Monads.

nest :: Monad m => [a] -> [m a] Source #

Move a monad inside a list.

Mapping.

map2 :: (a -> b) -> [[a]] -> [[b]] Source #

Map at the second level.

zipf Source #

Arguments

:: [a -> b]

The list of functions to be applied

-> [a]

The list of elements to which the functions will be applied

-> [b]

The result of the function applications

The zipf function applies a list of functions to corresponding elements in a list.

Lookups.

lookupWithDefault Source #

Arguments

:: Eq a 
=> b

The default value.

-> a

The key.

-> [(a, b)]

The associations.

-> b

The value for the key, or the default if the key is not present.

Look up a value in an association list.

lookupWithDefaultFunction Source #

Arguments

:: Eq a 
=> (a -> b)

The function for generating the default value.

-> a

The key.

-> [(a, b)]

The associations.

-> b

The value for the key, or the default if the key is not present.

Look up a value in an association list.

Padding, stripping, and pruning.

replicateHead Source #

Arguments

:: Int

Number of times to replicate the head.

-> [a]

The list.

-> [a]

The list with the replicas of the head.

Relicating the head of a list.

padHead Source #

Arguments

:: Int

Length of result.

-> a

Item to use for padding.

-> [a]

The list.

-> [a]

The padded list.

Pad the head of a list.

padTail Source #

Arguments

:: Int

Length of the result.

-> a

Item to use for padding.

-> [a]

The list.

-> [a]

THe padded list.

Pad the tail of a list.

chunk Source #

Arguments

:: Int

Length of the chunks.

-> [a]

The list.

-> [[a]]

The chunked list.

Deprecated: Use chunksOf instead.

Break a list into equally sized chunks.

stripHead Source #

Arguments

:: Eq a 
=> a

The item to remove from the start of list.

-> [a]

The list.

-> [a]

The list without the leading items.

Remove leading items from a list.

discardEnds Source #

Arguments

:: [a]

The list

-> [a]

The interior of the list

The discard function removes the first and last elements from a list.

removeDuplicates :: Eq a => [a] -> [a] Source #

Remove duplicates from a list, maintaining its order.

removeDuplicatesBy Source #

Arguments

:: (a -> a -> Bool)

Equality test function.

-> [a]

The list.

-> [a]

The list with duplicates removed.

Remove duplicates from a list, maintaining its order.

extract :: (a -> Bool) -> [a] -> ([a], Maybe a) Source #

Extract one element from a list.

rollback Source #

Arguments

:: [a]

The list to be reversed and prepended.

-> [a]

The list to be appended.

-> [a]

The resulting list

Reverse a first list and add it to a second one.

Splitting.

splitAtMatches Source #

Arguments

:: Eq a 
=> a

The separatrix.

-> [a]

The list.

-> [[a]]

The split list.

Deprecated: Use wordsBy instead.

Split up a list at every match of a particular item.

splitAround :: Int -> [a] -> ([a], a, [a]) Source #

Split a list around a particular element.