Unique 0.4.4 → 0.4.5
raw patch · 2 files changed
+36/−10 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.List.Unique: isRepeated :: Eq a => a -> [a] -> Maybe Bool
+ Data.List.Unique: isUnique :: Eq a => a -> [a] -> Maybe Bool
Files
- Data/List/Unique.hs +35/−9
- Unique.cabal +1/−1
Data/List/Unique.hs view
@@ -13,6 +13,8 @@ module Data.List.Unique ( complex+ , isUnique+ , isRepeated , sortUniq , repeated , repeatedBy@@ -25,11 +27,10 @@ where -import Data.List (group, sort, sortBy)+import Data.List (group, sort, sortBy, (\\)) import Control.Applicative (liftA2) import Data.Function (on)-import Data.List ((\\)) import Data.List.Extra (nubOrd) import Data.Tuple (swap) @@ -94,26 +95,28 @@ -- | 'complex' function is a complex investigation of the list. It returns triple: ----- * first - all elements without duplicates.+-- * the first - all elements with removed duplicates (like 'sortUniq' but the result is not sorted) ----- * second - the elements that are repeated at least once in the list (result is the same as 'repeated' but not sorted)+-- * the second - the elements that are repeated at least once in the list (result is the same as 'repeated' but not sorted) ----- * third - the unique elements that do not have duplicates (result is the same as 'unique' 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+-- '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 -- complex :: Eq a => [a] -> ([a], [a], [a])-complex = triplet reverse . (\(z,y) -> (z, y, (z \\ y) )) . go ([], [])+complex = triplet reverse . (\(z,y) -> (z, y, z \\ y )) . go ([], []) where go (occurred, repeated') [] = (occurred, repeated') go (occurred, repeated') (x:xs)- | elem x repeated' = go (occurred, repeated') xs- | elem x occurred = go (occurred, x:repeated') xs+ | x `elem` repeated' = go (occurred, repeated') xs+ | x `elem` occurred = go (occurred, x:repeated') xs | otherwise = go (x:occurred, repeated') xs triplet :: (a -> b) -> (a, a, a) -> (b, b, b)@@ -132,3 +135,26 @@ occurrences :: Ord a => [a] -> [(Int, [a])] occurrences = merge . map swap . count_++-- | '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+--++isUnique :: Eq a => a -> [a] -> Maybe Bool+isUnique x = checkNumber . countElem x+ where checkNumber 0 = Nothing+ checkNumber 1 = Just True+ checkNumber _ = Just False++-- | 'isRepeated' is a reverse function to 'isUnique'+--+-- Since 0.4.5+isRepeated :: Eq a => a -> [a] -> Maybe Bool+isRepeated x = fmap not . isUnique x
Unique.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.4.4+version: 0.4.5 -- A short (one-line) description of the package. synopsis: It provides the functionality like unix "uniq" utility