Unique 0.4.3 → 0.4.4
raw patch · 2 files changed
+47/−7 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.List.Unique: complex :: Eq a => [a] -> ([a], [a], [a])
+ Data.List.Unique: occurrences :: Ord a => [a] -> [(Int, [a])]
Files
- Data/List/Unique.hs +46/−6
- Unique.cabal +1/−1
Data/List/Unique.hs view
@@ -12,12 +12,14 @@ module Data.List.Unique (- sortUniq+ complex+ , sortUniq , repeated , repeatedBy , unique , count , count_+ , occurrences , countElem ) where@@ -27,7 +29,9 @@ import Control.Applicative (liftA2) import Data.Function (on)+import Data.List ((\\)) import Data.List.Extra (nubOrd)+import Data.Tuple (swap) -- | 'sortUniq' sorts the list and removes the duplicates of elements. Example: --@@ -81,14 +85,50 @@ count_ :: Ord a => [a] -> [(a, Int)] count_ = sortBy (compare `on` snd) . count --- | 'occurrences' finds all elements of each occurrences.---- occurrences :: Ord a => [a] -> [(1,a)]--- occurrences =- -- | 'countElem' gets the number of occurrences of the specified element. Example: -- -- > countElem 'o' "foo bar" == 2 countElem :: Eq a => a -> [a] -> Int countElem x = length . filter (== x)++-- | 'complex' function is a complex investigation of the list. It returns triple:+--+-- * first - all elements without duplicates.+--+-- * 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)+--+-- '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 "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 ([], [])+ 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+ | otherwise = go (x:occurred, repeated') xs++triplet :: (a -> b) -> (a, a, a) -> (b, b, b)+triplet f (x, y, z) = (f x, f y, f z)++merge :: Eq a => [(a,b)] -> [(a,[b])]+merge [] = []+merge ((x,y):xs) = (x, y : map snd ys) : merge zs+ where (ys,zs) = span ( (== x) . fst) xs++-- | '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+--++occurrences :: Ord a => [a] -> [(Int, [a])]+occurrences = merge . map swap . count_
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.3+version: 0.4.4 -- A short (one-line) description of the package. synopsis: It provides the functionality like unix "uniq" utility