Copyright | (c) Volodymyr Yashchenko |
---|---|

License | BSD3 |

Maintainer | ualinuxcn@gmail.com |

Stability | Unstable |

Portability | portable |

Safe Haskell | Safe |

Language | Haskell2010 |

Library provides the functions to find unique and duplicate elements in the list

## Synopsis

- complex :: Eq a => [a] -> ([a], [a], [a])
- isUnique :: Eq a => a -> [a] -> Maybe Bool
- isRepeated :: Eq a => a -> [a] -> Maybe Bool
- sortUniq :: Ord a => [a] -> [a]
- repeated :: Ord a => [a] -> [a]
- repeatedBy :: Ord a => (Int -> Bool) -> [a] -> [a]
- unique :: Ord a => [a] -> [a]
- allUnique :: Ord a => [a] -> Bool
- count :: Ord a => [a] -> [(a, Int)]
- count_ :: Ord a => [a] -> [(a, Int)]
- occurrences :: Ord a => [a] -> [(Int, [a])]
- countElem :: Eq a => a -> [a] -> Int

# Documentation

complex :: Eq a => [a] -> ([a], [a], [a]) Source #

`complex`

function is a complex investigation of the list. It returns triple:

- the first - all elements with removed duplicates (like
`sortUniq`

but the result is not sorted) - the second - the elements that are repeated at least once in the list (result is the same as
`repeated`

but not sorted) - the third - the unique elements that do not have duplicates (result is the same as
`unique`

but not sorted)

`complex`

does not sort the resulted elements of triple as well as it can be used for types that does not have Ord instance.

Anyway, it's better to use `sortUniq`

, `repeated`

and `unique`

instead of `complex`

when type `a`

has Ord instance.

complex "This is the test line" == ("This teln","is hte","Tln")

Since 0.4.4

isUnique :: Eq a => a -> [a] -> Maybe Bool Source #

`isUnique`

function is to check whether the given element is unique in the list or not.

It returns Nothing when the element does not present in the list. Examples:

isUnique 'f' "foo bar" == Just True isUnique 'o' "foo bar" == Just False isUnique '!' "foo bar" == Nothing

Since 0.4.5

isRepeated :: Eq a => a -> [a] -> Maybe Bool Source #

`isRepeated`

is a reverse function to `isUnique`

Since 0.4.5

sortUniq :: Ord a => [a] -> [a] Source #

`sortUniq`

sorts the list and removes the duplicates of elements. Example:

sortUniq "foo bar" == " abfor"

repeated :: Ord a => [a] -> [a] Source #

`repeated`

finds only the elements that are present more than once in the list. Example:

repeated "foo bar" == "o"

repeatedBy :: Ord a => (Int -> Bool) -> [a] -> [a] Source #

The repeatedBy function behaves just like repeated, except it uses a user-supplied equality predicate.

repeatedBy (>2) "This is the test line" == " eist"

unique :: Ord a => [a] -> [a] Source #

`unique`

gets only unique elements, that do not have duplicates.
It sorts them. Example:

unique "foo bar" == " abfr"

allUnique :: Ord a => [a] -> Bool Source #

`allUnique`

checks whether all elements of the list are unique

allUnique "foo bar" == False allUnique ['a'..'z'] == True allUnique [] == True (!)

Since 0.4.7

count :: Ord a => [a] -> [(a, Int)] Source #

`count`

of each element in the list, it sorts by keys (elements). Example:

count "foo bar" == [(' ',1),('a',1),('b',1),('f',1),('o',2),('r',1)]

count_ :: Ord a => [a] -> [(a, Int)] Source #

`count_`

of each elements in the list, it sorts by their number. Example:

count_ "foo bar" == [(' ',1),('a',1),('b',1),('f',1),('r',1),('o',2)]

occurrences :: Ord a => [a] -> [(Int, [a])] Source #

`occurrences`

like `count`

or `count_`

but shows the list of elements that occur X times

occurrences "This is the test line" == [(1,"Tln"),(2,"h"),(3,"eist"),(4," ")]

Since 0.4.4