packages feed

Unique (empty) → 0.1.0.0

raw patch · 4 files changed

+168/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ Data/List/Unique.hs view
@@ -0,0 +1,69 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Data.List.Unique+-- Copyright   :  (c) Volodymyr Yaschenko+-- License     :  BSD3+-- +-- Maintainer  :  ualinuxcn@gmail.com+-- Stability   :  Unstable+-- Portability :  portable+--+-----------------------------------------------------------------------------++module Data.List.Unique +   (sortUniq +  , repeated+  , unique+  , count+  , count_+  , countElem+    ) where ++import Data.List (sort,group,nub,filter,map,length)+import Prelude hiding (map,filter,length) ++-- | 'sortUniq' sorts the list and removes the duplicates of elements. Example: +--+-- sortUniq "foo bar" == " abfor"++sortUniq :: Ord a => [a] -> [a]+sortUniq = nub . sort++filterByLength :: Ord a => (Int -> Bool) -> [a] -> [[a]]+filterByLength p = filter (p . length) . group . sort++-- | 'repeated' finds only the elements that are present more than once in the list. Example: +--+--  repeated  "foo bar" == "o" ++repeated :: Ord a => [a] -> [a]+repeated = map head . filterByLength (>1)++-- | 'unique' gets only unique elements, those that do not have duplicates.  +-- It sorts them. Example: +--+--  unique  "foo bar" == " abfr"+  +unique :: Ord a => [a] -> [a]+unique = concat . filterByLength (==1)++-- | 'count' the elements in the list, 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)]+count = map (\x -> (head x,length x)) . group . sort++-- | 'count_' the elements in the list, sorts by values. Example: +--+--  count_ "foo bar" == [(' ',1),('a',1),('b',1),('f',1),('r',1),('o',2)]++count_ :: Ord a => [a] -> [(a, Int)]+count_ = map (\(x,y) -> (y,x)) . sort . map (\x -> (length x,head x)) . group . sort  ++-- | 'countElem' gets the amount of occurrences of the specified element. Example:  +--+--  countElem 'o' "foo bar" == Just 2++countElem :: Ord a => a -> [a] -> Maybe Int+countElem x = lookup x . count
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Volodymyr Yaschenko++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Volodymyr Yaschenko nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Unique.cabal view
@@ -0,0 +1,67 @@+-- Initial Unique.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                Unique++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            Provides with the functionality like unix "uniq" utility++-- A longer description of the package.+description:      Module provides with functions to find unique and duplicate elements in the list   ++-- The license under which the package is released.+license:             BSD3++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Volodymyr Yaschenko++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          ualinuxcn@gmail.com++-- A copyright notice.+-- copyright:           ++category:            Data++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+-- extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10+++library+  -- Modules exported by the library.+  exposed-modules:      Data.List.Unique+  +  -- Modules included in this library but not exported.+  -- other-modules:      +  +  -- LANGUAGE extensions used by modules in this package.+  -- other-extensions:    +  +  -- Other library packages from which modules are imported.+  build-depends:       base >=4.7 && <4.8+  +  -- Directories containing source files.+  -- hs-source-dirs:      +  +  -- Base language which the package is written in.+  default-language:    Haskell2010+