Copyright | (c) Volodymyr Yashchenko |
---|---|
License | BSD3 |
Maintainer | ualinuxcn@gmail.com |
Stability | Unstable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Library provides functions to find unique and duplicate elements in the list. Unlike Unique or UniqueStrict modules this one uses Data.HashMap.Strict for calculation.
The elements in the list can be unsorted (do not have an instance of Ord class, but Hashable is needed). This implementation is good for ByteStrings.
- isUnique :: (Hashable a, Eq a) => a -> [a] -> Maybe Bool
- isRepeated :: (Hashable a, Eq a) => a -> [a] -> Maybe Bool
- removeDuplicates :: (Hashable a, Eq a) => [a] -> [a]
- repeated :: (Hashable a, Eq a) => [a] -> [a]
- repeatedBy :: (Hashable a, Eq a) => (Int -> Bool) -> [a] -> [a]
- unique :: (Hashable a, Eq a) => [a] -> [a]
- allUnique :: (Hashable a, Eq a) => [a] -> Bool
- count :: (Hashable a, Eq a) => [a] -> [(a, Int)]
- count_ :: (Hashable a, Eq a) => [a] -> [(a, Int)]
Documentation
isUnique :: (Hashable a, 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.7.2
isRepeated :: (Hashable a, Eq a) => a -> [a] -> Maybe Bool Source #
isRepeated
is a reverse function to isUnique
Since 0.4.7.2
removeDuplicates :: (Hashable a, Eq a) => [a] -> [a] Source #
removeDuplicates
removes the duplicates of elements. Example:
removeDuplicates "foo bar" == " abrfo"
repeated :: (Hashable a, Eq a) => [a] -> [a] Source #
repeated
finds only the elements that are present more than once in the list. Example:
repeated "foo bar" == "o"
repeatedBy :: (Hashable a, Eq 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" == " stei"
unique :: (Hashable a, Eq a) => [a] -> [a] Source #
unique
gets only unique elements, that do not have duplicates.
unique "foo bar" == " abrf"
allUnique :: (Hashable a, Eq 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.2